Android获取某应用所申请的权限

    应用在执行某些动作时需要向系统申请权限,比如启动摄像头,打电话等。如何知道某个应用申请了哪些权限?在安装时候可以看到,也可以在权限管理的应用中看到。还可以写一个应用来获取。我这里把写死了。其实可以做一个对话框,输入应用的包名,然后获取该应用所申请的权限。代码不多,直接贴出来。

package com.shengteng.checkpermissions;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends Activity {
    //想要查看申请权限的包的包名
    String mPackName = "com.fey.bclient";
    boolean[] mPM=new boolean[13];
    String[] mPermissionName={"连接互联网权限","连接网络权限","改变网络连接权限","改变wifi状态权限","连接wifi权限","读取电话号码权限","发送短信权限","读短信权限","写短信权限","删除短信权限","挂载-卸载文件系统权限","写SD卡权限","读SD卡权限"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView = (TextView) findViewById(R.id.gettextview);
        textView.setText("");
        //获取包管理工具
        PackageManager pm = getPackageManager();

        mPM[0] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.INTERNET", mPackName));
        mPM[1] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.ACCESS_NETWORK_STATE", mPackName));
        mPM[2] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.CHANGE_NETWORK_STATE", mPackName));
        mPM[3] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.CHANGE_WIFI_STATE", mPackName));
        mPM[4] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.ACCESS_WIFI_STATE", mPackName));
        mPM[5] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_PHONE_STATE", mPackName));
        mPM[6] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.SEND_SMS", mPackName));
        mPM[7] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_SMS", mPackName));
        mPM[8] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.WRITE_SMS", mPackName));
        mPM[9] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.RECEIVE_SMS", mPackName));
        mPM[10] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.MOUNT_UNMOUNT_FILESYSTEMS", mPackName));
        mPM[11] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", mPackName));
        mPM[12] = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_EXTERNAL_STORAGE", mPackName));

        for(int i=0;i< mPM.length;i++){
            if(mPM[i]){
                Log.i("TAG",""+mPM[i]);
                textView.append(mPermissionName[i]+"  "+"true"+"\n");
            }else{
                //textView.setTextColor(Color.rgb(255, 0, 0));
                textView.append(mPermissionName[i]+"  "+"false"+"\n");
            }
        }
    }
}

你可能感兴趣的:(Android实例,Android汇总)