自启动相关

2018-04-28  本文已影响0人  颤抖的闪电
//    获取所有开机启动应用
    public List<String> listBootApps() {
        List<String> bootAppNames = new ArrayList<String>();
        PackageManager pm = mFragment.getActivity().getPackageManager();
//获取所有安装的App的信息
        List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (ApplicationInfo appInfo : appInfos) {
            if (appInfo.packageName.equals("com.zzc_trackingreact")) {

                int i = ContextCompat.checkSelfPermission(mFragment.getActivity(), Manifest.permission.RECEIVE_BOOT_COMPLETED);

//                if (ContextCompat.checkSelfPermission(mFragment.getActivity(), Manifest.permission.RECEIVE_BOOT_COMPLETED)
//                        != PackageManager.PERMISSION_GRANTED) {
//                    // 没有权限,可以在这里重新申请权限。
//                }else{
//                    // 有权限了。
//                }

                Log.d("自启动相关", appInfo.toString());
                int iBoot = pm.checkPermission("android.permission.RECEIVE_BOOT_COMPLETED", appInfo.packageName);
                if (iBoot == PackageManager.PERMISSION_GRANTED) {
                    String appName = pm.getApplicationLabel(appInfo).toString();
                    bootAppNames.add(appName);
                }
            }
        }
        return bootAppNames;
    }

    private void getPermissions() {
        PackageManager packManager = mFragment.getActivity().getPackageManager();
        List<ApplicationInfo> infos = packManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
//获取到安装的App列表
        for (ApplicationInfo info : infos) {
            if (info.packageName.equals("com.zzc_trackingreact")) {
                Log.d("app", "appName--->" + packManager.getApplicationLabel(info) + "");
                try {
                    PackageInfo packInfo = packManager.getPackageInfo(info.packageName, PackageManager.GET_PERMISSIONS);
                    String permissons[] = packInfo.requestedPermissions;
//获取该app的所有权限
                    int length = permissons.length;
                    for (int i = 0; i < length; i++) {
                        Log.d("app", permissons[i]);
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
//                    e.printStackTrace();
                }
            }

        }
    }

    private void getPermission(){
        ComponentName localComponentName = new ComponentName(mFragment.getActivity(), WakeReceiver.class);
        int i = mFragment.getActivity().getPackageManager().getComponentEnabledSetting(localComponentName);
    }
上一篇下一篇

猜你喜欢

热点阅读