另一个Android应用程序运行时一个Android应用程序能知道呢? [英] Can an Android application know when another Android application is running?
本文介绍了另一个Android应用程序运行时一个Android应用程序能知道呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设应用程序的Foo的鸡蛋都是一样的Android设备上。有可能为任一应用程序,以获取设备上的所有应用程序的列表。有可能是一个应用程序知道另一个应用程序已运行了多长时间?
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.
这篇关于另一个Android应用程序运行时一个Android应用程序能知道呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文