I need to show the last accessed app information in my app. How can i get this information?
You can use this code to get the list of applications:
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
String activityName = rInfo.activityInfo.name;
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
pkg = rInfo.activityInfo.applicationInfo.packageName;
if (pm.getLaunchIntentForPackage(pkg) == null) {
continue;
}
String label = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
arrayList.add(new AppEntry(label, activityName, pkg, null));
}
// How to detect which is the current top activity.
public boolean whatIsCurrentActivity()
{
ActivityManager am = (ActivityManager) mContext.getSystemService(mContext.ACTIVITY_SERVICE);
List ActivityManager.RunningTaskInfo taskInfo = am.getRunningTasks(1);
if(taskInfo != null ){
System.out.println("Top activity - Package name of the process is "+taskInfo.get(0).topActivity.getPackageName() );
}