How Can I Get The Package Name Of 2nd Top Activity Which Is In Other Package?
here in my case, a app invokes a service and the service will inturn starts an activity. My problem here is to get the app package which invokes that service. Can anybody help me t
Solution 1:
I found this directly from android source and it works fine :)
finalActivityManageram= (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(3, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
for (inti=0, index = 0; i < 3 && (index < 3); ++i) {
final ActivityManager.RecentTaskInforecentInfo= recentTasks.get(i);
Intentintent=newIntent( recentInfo.baseIntent);
if ( recentInfo.origActivity != null) {
intent.setComponent( recentInfo.origActivity);
}
finalPackageManagerpm= getPackageManager();
finalResolveInforesolveInfo= pm.resolveActivity(intent, 0);
finalActivityInfoinfo= resolveInfo.activityInfo;
finalStringtitle= info.loadLabel(pm).toString();
Log.d("hello"," "+title+" "+info.packageName);
finalImageViewiv= (ImageView)findViewById(R.id.imageView1);
iv.setImageDrawable(info.loadIcon(pm));
++index;
}
Solution 2:
Try this
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(1).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
returntrue;
}
}
It may useful to you to get second top activity.
Post a Comment for "How Can I Get The Package Name Of 2nd Top Activity Which Is In Other Package?"