Assume Applications Foo an Eggs are on the same Android device. It's possible for either application to get a list of all applications on the device. Is it p开发者_如何学JAVAossible for one application to know if another application has run and for how long?
You can get a list of installed applications by using the PackageManager. Code from here:
public class AppList extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
}
}
To see the currently running apps, you can use the ActivityManager.
This post explains how you can achieve that functionality in a generic way.
This post and this one have snippets of an Activity that lists the running applications, using ActivityManager
's getRunningAppProcesses()
.
This post explains how to get a list of all installed applications and then to choose one to run.
Take a look at the ActivityManager.
精彩评论