应用中关闭其他应用程序

android4.0在某应用中关闭其他应用程序:

STEP1:

在应用AndroidManifest.xml中添加权限:
  application标签中加上:
    android:sharedUserId="android.uid.system"
  manifest标签中添加权限:
    <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"/>

  android:sharedUserId="android.uid.system"将使应用运行在系统进程中,共享系统进程的数据,
  具有系统进程的权限。这可能带来的负面不确定问题不得而知了。

STEP2:

例如关闭打开的闹钟程序:
  String pakageName = "com.android.BBKClock"; 
  ActivityManager activityMgr;
  activityMgr = (ActivityManager)mContext.getSystemService(
  Context.ACTIVITY_SERVICE);

  activityMgr.forceStopPackage(packageName);

=========================================================

系统还提供了
  activityMgr.killPackageProcessesLocked(packageName);
仅需要权限
  <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
但是却始终无法关闭后台程序,仅仅是发送了一些停止的广播。具体还需要看代码。

猜你喜欢

转载自blog.csdn.net/weixin_38503885/article/details/80506630