I need to show the last accessed app information in my app. How can i get this information?
Asked
Active
Viewed 370 times
1
-
http://stackoverflow.com/questions/8388028/is-there-a-list-of-all-stock-messaging-apps-package-names-for-all-android-phone/8388163#8388163 – Padma Kumar Dec 28 '11 at 11:49
-
@PadmaKumar From that i wil get packagename, version. But can we get the information of last access date of that app?? – Cintu Dec 28 '11 at 11:54
-
android is not storing any dates, you need to write an service to store it in DB or file. when ever you are opening an application your need to save that package name and sys current time. so that you can get the last access data. – Padma Kumar Dec 28 '11 at 11:59
-
@ Padmakumar - Thanks.. my another question if i open any other application eg. facebook. How my custom application service will come to know device opened facebook app. – Cintu Dec 29 '11 at 08:01
-
http://stackoverflow.com/questions/3873659/android-how-can-i-get-the-current-foreground-activity-from-a-service http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android – Padma Kumar Dec 29 '11 at 09:10
2 Answers
2
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));
}

Shaunak
- 17,377
- 5
- 53
- 84
0
// 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() );
}

Padma Kumar
- 19,893
- 17
- 73
- 130