如何阻止Android应用程序使用权限

时间:2012-03-19 00:11:49

标签: android permissions android-applicationinfo

如果某个应用程序有“android.permission.CAMERA”,并且我希望我的应用程序在尝试访问相机硬件时阻止使用此权限,“出于安全原因”我该如何阻止该进程?< / p>

*注意:我们假设我的应用具有所有权限......

3 个答案:

答案 0 :(得分:4)

您需要使用Device Administration API。从Android 4.0开始,您可以禁用setCameraDisabled

使用相机

答案 1 :(得分:3)

我不知道任何非根本解决方案,但是在Android市场上有一个名为“Android Permission Blocker”的应用程序可以在应用程序基础上阻止个人应用程序权限。它只花了99美分,所以我尝试了它,并且从那以后一直使用它。值得我认为每一分钱。

答案 2 :(得分:2)

我讨厌程序员说&#34;这是不可能的!&#34; 我认为&#34;总有一条出路&#34; < / p>

        public static void      killAppByPermission (Context context, String permissionToKill)
        {
            try
            {
                PackageManager p = context.getPackageManager();
                final List <PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
                for(PackageInfo pInfo:appinstall)
                {
                    String[] reqPermission = pInfo.requestedPermissions;
                    if(reqPermission != null)
                    {
                        for(int i=0;i<reqPermission.length;i++)
                        {
                            if (((String)reqPermission[i]).toLowerCase().contains(permissionToKill.toLowerCase()))
                            {
                                killAppByPackName(pInfo.packageName.toString());
                                break;
                            }
                        }
                    }
                }
            }
            catch (Throwable t){t.printStackTrace();}
        }

    public static void      killAppByPackName   (String packageToKill)
    {
        try
        {
            ActivityManager actvityManager = (ActivityManager) Sett.context.getSystemService(Context.ACTIVITY_SERVICE);
            final List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
            for (RunningAppProcessInfo runningAppProcessInfo : procInfos) 
            {
                //Log.e("running",runningAppProcessInfo.processName);
                if(runningAppProcessInfo.processName.toLowerCase().contains(packageToKill.toLowerCase())) 
                {
                    android.os.Process.sendSignal(runningAppProcessInfo.pid, android.os.Process.SIGNAL_KILL);
                    actvityManager.killBackgroundProcesses(packageToKill);
                    //Log.e("killed", "!!! killed "+ packageToKill);
                }           
            }
        }
        catch (Throwable t){History.Error(t);}
    }

    public static void      killAppByName       (Context context, String appNameToKill)
    {
        try
        {
            ActivityManager  manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
            for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
            {
                if (process.processName.toLowerCase().contains(appNameToKill.toLowerCase()))
                {
                    //Log.e("killed", process.processName);
                    manager.killBackgroundProcesses(process.processName);
                    break;
                }
            }
        }
        catch (Throwable t){t.printStackTrace();}
    }