Android的权限拒绝:forceStopPackage() [英] Android Permission Denial: forceStopPackage()

查看:6760
本文介绍了Android的权限拒绝:forceStopPackage()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用杀死其他应用程序的 forceStopPackage()。但我的应用程序显示运行时错误。

I am try to kill another application using forceStopPackage(). But my application shows runtime error.

错误

java.lang.SecurityException: Permission Denial: forceStopPackage() from pid=10377, uid=10200 requires android.permission.FORCE_STOP_PACKAGES

在我的清单文件中添加以下权限。

In my manifest file i added the following permissions.

<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

    <permission
        android:name="android.permission.FORCE_STOP_PACKAGES"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signature"
        android:sharedUserId="android.uid.system" />

code

ActivityManager am = (ActivityManager) 
         context.getSystemService(Context.ACTIVITY_SERVICE);
Method forceStopPackage = am.getClass().
          getDeclaredMethod("forceStopPackage", String.class);  
    forceStopPackage.setAccessible(true);  
    forceStopPackage.invoke(am, packageName);

如何解决问题。

推荐答案

您要添加的权限在AndroidManifest.xml像下面。

You have to add the permission in the AndroidManifest.xml like below.

<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"></uses-permission>

确认只有当你的应用程序与系统签名密钥,操作系统将允许停止其他应用。

Make sure only if your app is signed with system key os will allow to stop other apps.

这篇关于Android的权限拒绝:forceStopPackage()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆