ActivityManager mActivityManager = (ActivityManager)
this
getSystemService(ACTIVITY_SERVICE);
List<ActivityManagerRunningAppProcessInfo>
mRunningProcess = mActivityManager
getRunningAppProcesses();
int i =
1;
for (ActivityManagerRunningAppProcessInfo amProcess :
mRunningProcess)
{
Logi("Application", (i++) + "PID: " +
amProcesspid
+ "(processName=" + amProcessprocessName +
"UID="+amProcessuid+")");
}
// 获得PackageManager对象
PackageManager pm = contextgetPackageManager();
ActivityManager am = (ActivityManager) context
getSystemService(ContextACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = amgetRunningTasks(100);
if (!tasksisEmpty()) {
ComponentName topActivity = tasksget(0)topActivity;
for (RunningTaskInfo info : tasks) {
// 查询这个后台任务的 启动Activity
Intent mainIntent = new Intent(IntentACTION_MAIN);
mainIntentsetPackage(topActivitygetPackageName());
mainIntentaddCategory(IntentCATEGORY_LAUNCHER);
// 通过查询,获得所有ResolveInfo对象
List<ResolveInfo> resolveInfos = pmqueryIntentActivities(
mainIntent, PackageManagerMATCH_DEFAULT_ONLY);
ResolveInfo reInfo = resolveInfosget(0);
// 获得该应用程序的启动Activity的name
String activityName = reInfoactivityInfoname;
// 获得应用程序的包名
String pkgName = reInfoactivityInfopackageName;
// 获得应用程序的Label
String appLabel = (String) reInfoloadLabel(pm);
Drawable icon = reInfoloadIcon(pm); // 获得应用程序图标
// 为应用程序的启动Activity 准备Intent
Intent launchIntent = new Intent();
launchIntentsetComponent(new ComponentName(pkgName,
activityName));
}
}
在minifest中注册该Activity时加上一个<intent-fiter> <action/></intent-filter> action中注明你的广播就OK了。
以上就是关于如何获取Android正在运行的应用和它的pid全部的内容,包括:如何获取Android正在运行的应用和它的pid、Android 有没有什么方法能够得到所有正在后台运行的Activity。、请问下Android里怎么获取桌面或系统里的某个Activity对象等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)