另一个Android应用程序运行时一个Android应用程序能知道呢?应用程序、Android

2023-09-06 05:12:41 作者:被窝哲学家

假设应用程序的Foo的鸡蛋都是一样的Andr​​oid设备上。有可能为任一应用程序,以获取设备上的所有应用程序的列表。有可能是一个应用程序知道另一个应用程序已运行了多长时间?

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 possible for one application to know if another application has run and for how long?

推荐答案

您可以通过使用的 PacketManager 。code从这里 :

You can get a list of installed applications by using the PacketManager. 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());
}
}

要看到当前运行的应用程序,你可以使用 ActivityManager

To see the currently running apps, you can use the ActivityManager.