Android permission description

question

We often apply for some related permissions when writing apk. If you want to know what each permission does, you can check where the permission is declared.

1. Three-party page:

https://manifestdestiny.reveb.la/

2. Source code comments

/frameworks/base/core/res/AndroidManifest.xml

    <!-- @SystemApi @TestApi Allows an application to write to internal media storage
         @deprecated This permission is no longer honored in the system and no longer adds
         the media_rw gid as a supplementary gid to the holder. Use the
         android.permission.MANAGE_EXTERNAL_STORAGE instead.
         @hide  -->
    <permission android:name="android.permission.WRITE_MEDIA_STORAGE"
        android:protectionLevel="signature|privileged" />

3. Custom permissions

Some applications will customize permissions, and instructions can be added when defining permissions.
For example, custom permissions in the launcher.

    <permission
        android:name="${packageName}.permission.READ_SETTINGS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signatureOrSystem"
        android:label="@string/permlab_read_settings"
        android:description="@string/permdesc_read_settings"/>

insert image description here
If the permission has no description or comment, it will be quite pitiful. You can only pray that the name of the authority can tell what it is.

Fortunately, the declarations and comments of permissions in the source code are relatively complete.

4. Use of custom permissions and permissions

The permission statement in the source code is here /frameworks/base/core/res/AndroidManifest.xml
used in all source code applications. There is a complete set of permission detection.

The apk can also declare its own permissions to restrict access to its own external requests.

5、demo

appA

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <uses-permission android:name="android.permission.INTERNET"/>
    //声明权限
    //等级标记为危险权限,需要动态申请
    <permission android:name="com.example.myapplication.MainActivity"
        android:icon="@drawable/ic_icon_mouse_37"
        android:label="@string/my_permission"
        android:description="@string/my_permission_description"
        android:protectionLevel="dangerous"
        />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:requiredForAllUsers="false"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:excludeFromRecents="true"
            android:permission="com.example.myapplication.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

appB

//注册权限
<uses-permission android:name="com.example.myapplication.MainActivity"/>

//button单击事件
        button.setOnClickListener(new View.OnClickListener() {
    
    
            @SuppressLint("NewApi")
            @Override
            public void onClick(View view) {
    
    
            //判断权限,有权限的话直接打开appA
            //没有权限则动态申请权限
                if (checkCallingOrSelfPermission("com.example.myapplication.MainActivity") == PackageManager.PERMISSION_GRANTED){
    
    
                    Intent intent = new Intent();
                    intent.setClassName("com.example.myapplication","com.example.myapplication.MainActivity");
                    startActivity(intent);
                }else{
    
    
                    requestPermissions(new String[]{
    
    "com.example.myapplication.MainActivity"},1001);
                }
            }
        });
//权限同意和拒绝弹提示框
@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    
    
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 1001 && "com.example.myapplication.MainActivity".equals(permissions[0])){
    
    
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
    
    
                Toast.makeText(this,"权限申请成功",Toast.LENGTH_SHORT).show();
            }else{
    
    
                Toast.makeText(this,"权限申请失败",Toast.LENGTH_SHORT).show();
            }
        }
    }

Guess you like

Origin blog.csdn.net/a396604593/article/details/130271222