2011-05-19 23 views
3

假设应用程序Foo an Eggs在同一个Android设备上。任何应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已运行以及运行了多久?Android应用程序能够知道另一个Android应用程序何时运行吗?

+0

可能的重复:http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android – djg 2011-05-19 19:59:17

回答

4

您可以使用PacketManager获取已安装应用程序的列表。从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

+0

感谢您的答案。非常刺激。 – 2011-05-20 17:13:02

1

post解释如何以通用的方式实现该功能。

postone有列出了运行应用程序的活动的片段,用ActivityManagergetRunningAppProcesses()

post解释了如何获取所有安装的应用程序的列表,然后选择要运行的应用程序。

+0

应该补充的是,您需要为清单添加一个权限,以使用getRunningTasks()或getRecentTasks()。确切地说android.permission.GET_TASKS。 – Maximus 2011-05-19 20:21:58

相关问题