get Permission App Map - Android App

Android examples for App:APK Information

Description

get Permission App Map

Demo Code


//package com.java2s;
import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;

import android.content.pm.PackageInfo;

public class Main {
    public static HashMap<String, ArrayList<PackageInfo>> mPermissionAppMap;
    public static List<PackageInfo> mPackages;

    private static HashMap<String, ArrayList<PackageInfo>> getPermissionAppMap() {
        //Permission as the key, array of packages that use that permission
        mPermissionAppMap = new HashMap<String, ArrayList<PackageInfo>>(128);

        for (PackageInfo pi : mPackages) {
            if (pi.requestedPermissions == null)
                continue;

            for (String permission : pi.requestedPermissions) {
                if (!mPermissionAppMap.containsKey(permission)) {
                    ArrayList<PackageInfo> arPi = new ArrayList<PackageInfo>(
                            20);//from  ww w.j av a  2s .c o  m
                    mPermissionAppMap.put(permission, arPi);
                }
                mPermissionAppMap.get(permission).add(pi);
            }
        }

        return mPermissionAppMap;
    }
}

Related Tutorials