有没有办法在android中获取每个权限的相关信息

有没有办法在android中获取每个权限的相关信息,android,permissions,Android,Permissions,Android让开发者在应用程序可以使用工具或硬件之前声明权限,我已经创建了一个类来存储每个权限的描述,比如权限名称,好的名称,以及权限所做的描述。现在,我可以通过编程方式初始化每个对象,从中获取信息 该类的代码是 package org.owasp.seraphimdroid.customclasses; public class PermissionData { private String permission; private String permissionName

Android让开发者在应用程序可以使用工具或硬件之前声明权限,我已经创建了一个类来存储每个权限的描述,比如权限名称,好的名称,以及权限所做的描述。现在,我可以通过编程方式初始化每个对象,从中获取信息

该类的代码是

package org.owasp.seraphimdroid.customclasses;

public class PermissionData {
    private String permission;
    private String permissionName;
    private String description;
    private String regularUseDescription;
    private String maliciousUseDescription;
    private int weight;

    public PermissionData(String permission){
        this.permission = permission;
        setData();
    }

    private void setData(){
        weight = 0;
    }   

    //Getters and setter
    public String getPermissionName() {
        return permissionName;
    }
    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }
    public int getWeight() {
        return weight;
    }
    public void setWeight(int weight) {
        this.weight = weight;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getRegularUseDescription() {
        return regularUseDescription;
    }

    public void setRegularUseDescription(String regularUseDescription) {
        this.regularUseDescription = regularUseDescription;
    }

    public String getMaliciousUseDescription() {
        return maliciousUseDescription;
    }

    public void setMaliciousUseDescription(String maliciousUseDescription) {
        this.maliciousUseDescription = maliciousUseDescription;
    }



}
我还应该将这些对象存储为hashmap还是存储在数据库中?
这些方法主要用于根据权限显示活动中的信息。

使用
上下文。检查*
方法(来自
上下文
对象的以“检查”开头的方法),以检查是否授予了给定的权限。请看一个例子

请注意,无法在运行时添加权限

目前我能想到的存储对象数据的最简单方法是将它们写入数据库,将它们序列化为文件,或者将键值对写入SharedReference。这将取决于你认为什么更合适。hashmap与持久性无关;您可以选择它作为将数据保存在内存中并在应用程序执行期间访问数据的方法

Android开发者的培训有一节是关于。如果希望使用序列化,以下方法可能会很有用:

private void _serializeObject(Object object, String fileName) {
    String aboluteFilePath = getApplicationContext().getFilesDir().getPath() + File.separator + fileName;
    try {

        FileOutputStream fileOut = new FileOutputStream(absoluteFilePath);
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(object);
        out.close();
        fileOut.close();
    } catch (IOException e) {
        Log.e(TAG, "Error while serializing data to " + absoluteFilePath, e);
    }
}

private Object _deserializeObject(String fileName) {
    Object object = null;
    String absoluteFilePath = getApplicationContext().getFilesDir().getPath() + File.separator + fileName;
    try {
        FileInputStream fileIn = new FileInputStream(absoluteFilePath);
        ObjectInputStream in = new ObjectInputStream(fileIn);
        object = in.readObject();
        in.close();
        fileIn.close();
    } catch (FileNotFoundException e) {
        // You may want to ignore this exception as it will occur the first time the
        // data is deserialized unless you make sure serialization occurs before it.
    } catch (IOException e) {
        Log.e(TAG, IOException.class.getSimpleName() + " while deserializing from " + absoluteFilePath, e);
    } catch (ClassNotFoundException e) {
        Log.e(TAG, ClassNotFoundException.class.getSimpleName() + " while deserializing from " + absoluteFilePath, e);
    }

    return object;
}