Mark Hansen wrote:
> I'm trying to the the application and icons for Recent Tasks, but I
> can't seem to get the appInfo using the RecentTaskInfo. The
> getApplicationInfo call is what is failing due to the getPackageName()
> returning null.
>
>
> ActivityManager manager =
> (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
> List<RecentTaskInfo> tasks = manager.getRecentTasks(50, 1);
> for (int counter = 0; counter < tasks.size(); counter++)
> {
> RecentTaskInfo task = tasks.get(counter);
> PackageManager pm = this.getPackageManager();
>
> try {
>
> ApplicationInfo appInfo =
> pm.getApplicationInfo(task.origActivity.getPackageName(),0);
> String applicationName =
> getPackageManager().getApplicationLabel(appInfo).toString();
> Drawable icon = appInfo.loadIcon(pm);
> .....
>
> I've also tried:
>
> ApplicationInfo appInfo =
> pm.getApplicationInfo(task.baseIntent.getPackage(),0);
>
> In which getPackage() is returning null.. maybe I'm going about this
> the wrong way and was hoping for some tips?
It may be there's a way to get things to work going down the path you're
headed.
Personally, I'd look at the source to RecentApplicationsDialog and see
how they do it. You can find this in Google Code Search by searching on:
package:android recentapplicationsdialog
The reloadButtons() method uses getRecentTasks(). They create an Intent
for each task, use resolveActivity() on PackageManager to get the
ResolveInfo on the activity, then use loadLabel()/loadIcon() to get the
display stuff.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android App Developer Books: http://commonsware.com/books
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.