├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── wanjian
│ │ └── permission
│ │ └── demo
│ │ ├── App.java
│ │ ├── MainActivity.java
│ │ └── SecondAct.java
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ ├── activity_main.xml
│ └── activity_sec.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── permission
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── wanjian
│ │ └── permission
│ │ ├── OneKeyPerm.java
│ │ ├── PermissionActivity.java
│ │ └── WatchAuthorizationActivity.java
│ └── res
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 wanjian
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OneKeyPerm
2 | 一键申请Android权限
3 |
4 |
5 | ### OneKeyPerm接入说明
6 |
7 |
8 |
9 | OneKeyPerm不依赖任何业务Activity,支持多进程,只需一句静态代码就可以了
10 |
11 | 例如
12 |
13 | ```java
14 | 申请权限被拒绝后 不会 自动开启设置页面让用户手动开启权限
15 |
16 | OneKeyPerm.request(application, Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
17 | @Override
18 | public void onPermResult(String perm, boolean isGrant) {
19 | Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
20 | }
21 | });
22 | ```
23 |
24 | 或者
25 |
26 | ```java
27 | 申请权限被拒绝后 会 自动开启设置页面让用户手动开启权限
28 |
29 | OneKeyPerm.request(application, Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
30 | @Override
31 | public void onPermResult(String perm, boolean isGrant) {
32 | Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
33 | }
34 | },true);
35 | ```
36 |
37 |
38 |
39 | ### 原理分析
40 |
41 | * 每次通过context启动透明Activity`(PermissionActivity)`请求权限
42 |
43 | * 当权限被拒绝后启动另一个透明Activity `(WatchAuthorizationActivity)`,在`WatchAuthorizationActivity`中再次启动应用详情设置Activity,然后在`WatchAuthorizationActivity`的`onActivityResult`方法中再次检查是否已经手动授权,并通过Binder(解决多进程问题)通知调用者
44 |
45 |
46 | 备注:收回授权后Android会重启App
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 33
5 | defaultConfig {
6 | applicationId "com.wanjian.permission.demo"
7 | minSdkVersion 18
8 | targetSdkVersion 33
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(include: ['*.jar'], dir: 'libs')
22 | implementation 'com.android.support:appcompat-v7:26+'
23 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
24 | implementation project(':permission')
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/permission/demo/App.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission.demo;
2 |
3 | import android.app.Application;
4 |
5 | import com.wanjian.permission.OneKeyPerm;
6 |
7 | /**
8 | * Created by wanjian on 2018/1/2.
9 | */
10 |
11 | public class App extends Application {
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/permission/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission.demo;
2 |
3 | import android.Manifest;
4 | import android.app.ActivityManager;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.View;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.wanjian.permission.OneKeyPerm;
15 |
16 |
17 | public class MainActivity extends AppCompatActivity {
18 |
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | findViewById(R.id.btn1).setOnClickListener(v -> requestCameraPermission());
25 |
26 | findViewById(R.id.btn2).setOnClickListener(v -> requestStoragePermission());
27 |
28 | findViewById(R.id.btn3).setOnClickListener(v -> {
29 | showHomeScreen();
30 | new Handler().postDelayed(() -> requestCameraPermission(), 2000);
31 | });
32 |
33 | findViewById(R.id.btn4).setOnClickListener(v -> {
34 | showHomeScreen();
35 | new Handler().postDelayed(() -> requestStoragePermission(), 2000);
36 | });
37 |
38 | findViewById(R.id.btn5).setOnClickListener(v -> {
39 | finish();
40 | new Handler().postDelayed(() -> requestCameraPermission(), 2000);
41 | });
42 |
43 | findViewById(R.id.btn6).setOnClickListener(v -> {
44 | finish();
45 | new Handler().postDelayed(() -> requestStoragePermission(), 2000);
46 | });
47 |
48 |
49 | findViewById(R.id.newAct).setOnClickListener(v -> startActivity(new Intent(getApplicationContext(), SecondAct.class)));
50 | ((TextView) findViewById(R.id.tv)).setText(processName() + " " + android.os.Process.myPid());
51 |
52 | }
53 |
54 | private void requestStoragePermission() {
55 | OneKeyPerm.request(getApplication(), Manifest.permission.READ_EXTERNAL_STORAGE, "您需要允许读取文件权限,否则无法查看图片", new OneKeyPerm.OnPermResultListener() {
56 | @Override
57 | public void onPermResult(String perm, boolean isGrant) {
58 | Toast.makeText(MainActivity.this, "请求读取权限 " + isGrant, Toast.LENGTH_SHORT).show();
59 | }
60 | }, true);
61 | }
62 |
63 | private void showHomeScreen() {
64 | Intent intent = new Intent(Intent.ACTION_MAIN);
65 | intent.addCategory(Intent.CATEGORY_HOME);
66 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
67 | startActivity(intent);
68 | }
69 |
70 | private String processName() {
71 | int pid = android.os.Process.myPid();
72 | String processName;
73 | ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
74 | for (ActivityManager.RunningAppProcessInfo appProcess : am.getRunningAppProcesses()) {
75 | if (appProcess.pid == pid) {
76 | processName = appProcess.processName;
77 | return processName;
78 | }
79 | }
80 | return null;
81 | }
82 |
83 | private void requestCameraPermission() {
84 | OneKeyPerm.request(getApplication(), Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
85 | @Override
86 | public void onPermResult(String perm, boolean isGrant) {
87 | Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
88 | }
89 | }, true);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/permission/demo/SecondAct.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission.demo;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.app.ActivityManager;
6 | import android.content.Context;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.view.View;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.wanjian.permission.OneKeyPerm;
14 |
15 |
16 | /**
17 | * Created by wanjian on 2018/1/2.
18 | */
19 |
20 | public class SecondAct extends Activity {
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 |
26 | setContentView(R.layout.activity_sec);
27 |
28 | findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | OneKeyPerm.request(getApplication(), Manifest.permission.READ_EXTERNAL_STORAGE, "需要读取文件", new OneKeyPerm.OnPermResultListener() {
32 | @Override
33 | public void onPermResult(String perm, boolean isGrant) {
34 | Toast.makeText(SecondAct.this, "请求读取权限 " + isGrant, Toast.LENGTH_SHORT).show();
35 | }
36 | },true);
37 | }
38 | });
39 | ((TextView) findViewById(R.id.tv)).setText(processName() + " " + android.os.Process.myPid());
40 |
41 |
42 | }
43 |
44 | private String processName() {
45 | int pid = android.os.Process.myPid();
46 | String processName;
47 | ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
48 | for (ActivityManager.RunningAppProcessInfo appProcess : am.getRunningAppProcesses()) {
49 | if (appProcess.pid == pid) {
50 | processName = appProcess.processName;
51 | return processName;
52 | }
53 | }
54 | return null;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
24 |
25 |
31 |
32 |
38 |
39 |
45 |
46 |
52 |
53 |
59 |
60 |
61 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sec.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
19 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | One Key Permission
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:7.4.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/OneKeyPerm/6706322a2d7ee100a49d9d06d4e9442913aaa7ca/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 07 19:04:44 CST 2025
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/permission/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/permission/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion 33
4 |
5 | defaultConfig {
6 | minSdkVersion 18
7 | targetSdkVersion 33
8 | versionCode 1
9 | versionName "1.0"
10 |
11 |
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | implementation 'com.android.support:appcompat-v7:26.1.0'
26 | }
27 |
28 | buildscript {
29 | repositories {
30 | jcenter()
31 | google()
32 | }
33 | dependencies {
34 | classpath 'com.android.tools.build:gradle:7.4.2'
35 | }
36 | }
37 |
38 |
39 |
--------------------------------------------------------------------------------
/permission/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/permission/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/permission/src/main/java/com/wanjian/permission/OneKeyPerm.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.os.Binder;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.os.Looper;
12 | import android.os.Parcel;
13 | import android.os.RemoteException;
14 | import android.support.annotation.NonNull;
15 | import android.support.annotation.Nullable;
16 | import android.support.v4.content.ContextCompat;
17 |
18 | /**
19 | * Created by wanjian on 2017/12/29.
20 | */
21 |
22 | public class OneKeyPerm {
23 |
24 | static final String TIPS = "tips";
25 | static final String RECEIVER = "receiver";
26 | static final String ONE_KEY_PERM = OneKeyPerm.class.getName();
27 |
28 | public static void request(Context context,final String permission, String tips, final OnPermResultListener listener) {
29 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
30 | if (listener != null) {
31 | listener.onPermResult(permission, true);
32 | }
33 | return;
34 | }
35 |
36 | int permissionCheck = ContextCompat.checkSelfPermission(context, permission);
37 | if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
38 | if (listener != null) {
39 | listener.onPermResult(permission, true);
40 | }
41 | return;
42 | }
43 | Intent intent = new Intent(context, PermissionActivity.class);
44 | intent.putExtra(ONE_KEY_PERM, permission);
45 | intent.putExtra(TIPS, tips);
46 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
47 | Bundle bundle = new Bundle();
48 | bundle.putBinder(RECEIVER, new Binder() {
49 | @Override
50 | protected boolean onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
51 | if (listener != null) {
52 | String permission = data.readString();
53 | int result = data.readInt();
54 | setPermResult(listener, permission, result == PackageManager.PERMISSION_GRANTED);
55 | }
56 | return true;
57 | }
58 | });
59 | intent.putExtras(bundle);
60 |
61 | context.startActivity(intent);
62 | }
63 |
64 | public static void request(final Context context, final String permission, final String tips, final OnPermResultListener listener, boolean manualuthorize) {
65 | if (manualuthorize) {
66 | request(context,permission, tips, new OnPermResultListener() {
67 | @Override
68 | public void onPermResult(String perm, boolean isGrant) {
69 | if (!isGrant) {
70 | watchAuthorization(context,listener, tips, perm);
71 | } else if (listener != null) {
72 | setPermResult(listener, perm, isGrant);
73 | }
74 | }
75 | });
76 | } else {
77 | request(context,permission, tips, listener);
78 | }
79 | }
80 |
81 | private static void watchAuthorization(Context context, final OnPermResultListener listener, String tips, final String permission) {
82 | Intent intent = new Intent(context, WatchAuthorizationActivity.class);
83 | intent.putExtra(ONE_KEY_PERM, permission);
84 | intent.putExtra(TIPS, tips);
85 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
86 | Bundle bundle = new Bundle();
87 | bundle.putBinder(RECEIVER, new Binder() {
88 | @Override
89 | protected boolean onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
90 | if (listener != null) {
91 | String permission = data.readString();
92 | int result = data.readInt();
93 | setPermResult(listener, permission, result == PackageManager.PERMISSION_GRANTED);
94 | }
95 | return true;
96 | }
97 | });
98 | intent.putExtras(bundle);
99 | context.startActivity(intent);
100 | }
101 |
102 | private static void setPermResult(final OnPermResultListener listener, final String perm, final boolean result) {
103 | if (Looper.myLooper() == Looper.getMainLooper()) {
104 | listener.onPermResult(perm, result);
105 | } else {
106 | new Handler(Looper.getMainLooper()).post(new Runnable() {
107 | @Override
108 | public void run() {
109 | listener.onPermResult(perm, result);
110 | }
111 | });
112 | }
113 | }
114 | public interface OnPermResultListener {
115 | void onPermResult(String perm, boolean isGrant);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/permission/src/main/java/com/wanjian/permission/PermissionActivity.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.os.Bundle;
7 | import android.os.IBinder;
8 | import android.os.Parcel;
9 | import android.os.RemoteException;
10 | import android.support.annotation.NonNull;
11 | import android.support.annotation.Nullable;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.support.v4.content.ContextCompat;
14 | import android.support.v7.app.AlertDialog;
15 | import android.support.v7.app.AppCompatActivity;
16 | import android.text.TextUtils;
17 |
18 | import static com.wanjian.permission.OneKeyPerm.ONE_KEY_PERM;
19 | import static com.wanjian.permission.OneKeyPerm.RECEIVER;
20 | import static com.wanjian.permission.OneKeyPerm.TIPS;
21 |
22 |
23 | /**
24 | * Created by wanjian on 2017/12/29.
25 | */
26 |
27 | public class PermissionActivity extends AppCompatActivity {
28 | private final int REQUEST_CODE = 1;
29 | private IBinder receiver;
30 | @Override
31 | protected void onCreate(@Nullable Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | Intent intent = getIntent();
34 | Bundle bundle = intent.getExtras();
35 | if (bundle != null) {
36 | receiver = bundle.getBinder(RECEIVER);
37 | }
38 | final String perm = intent.getStringExtra(ONE_KEY_PERM);
39 | if (TextUtils.isEmpty(perm) || receiver == null) {
40 | finish();
41 | return;
42 | }
43 |
44 | if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
45 | // Should we show an explanation?
46 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, perm)) {
47 |
48 | // Show an expanation to the user *asynchronously* -- don't block
49 | // this thread waiting for the user's response! After the user
50 | // sees the explanation, try again to request the permission.
51 | String tips = intent.getStringExtra(TIPS);
52 | if (TextUtils.isEmpty(tips)) {
53 | ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{perm}, REQUEST_CODE);
54 | } else {
55 | new AlertDialog.Builder(PermissionActivity.this).setTitle(tips).setNegativeButton("确定", new DialogInterface.OnClickListener() {
56 | @Override
57 | public void onClick(DialogInterface dialog, int which) {
58 | ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{perm}, REQUEST_CODE);
59 | }
60 | }).create().show();
61 | }
62 | } else {
63 | // No explanation needed, we can request the permission.
64 | ActivityCompat.requestPermissions(this, new String[]{perm}, REQUEST_CODE);
65 | // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
66 | // app-defined int constant. The callback method gets the
67 | // result of the request.
68 | }
69 | } else {
70 | setResult(perm,PackageManager.PERMISSION_GRANTED);
71 | finish();
72 | }
73 | }
74 |
75 | @Override
76 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
77 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
78 | switch (requestCode) {
79 | case REQUEST_CODE: {
80 | // If request is cancelled, the result arrays are empty.
81 | if (grantResults.length > 0) {
82 |
83 | // permission was granted, yay! Do the
84 | // contacts-related task you need to do.
85 | setResult(permissions[0], grantResults[0]);
86 | } else {
87 | // permission denied, boo! Disable the
88 | // functionality that depends on this permission.
89 | }
90 | finish();
91 | }
92 |
93 | }
94 | }
95 |
96 | private void setResult(String perm, int result) {
97 | Parcel parcel = Parcel.obtain();
98 | parcel.writeString(perm);
99 | parcel.writeInt(result);
100 | try {
101 | receiver.transact(0, parcel, Parcel.obtain(), IBinder.FLAG_ONEWAY);
102 | } catch (RemoteException e) {
103 | throw new RuntimeException(e);
104 | }
105 | }
106 |
107 | @Override
108 | public void finish() {
109 | super.finish();
110 | overridePendingTransition(0, 0);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/permission/src/main/java/com/wanjian/permission/WatchAuthorizationActivity.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.permission;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.os.Parcel;
8 | import android.os.RemoteException;
9 | import android.provider.Settings;
10 | import android.support.annotation.Nullable;
11 | import android.support.v4.content.ContextCompat;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.text.TextUtils;
14 | import android.widget.Toast;
15 |
16 | import static com.wanjian.permission.OneKeyPerm.ONE_KEY_PERM;
17 | import static com.wanjian.permission.OneKeyPerm.RECEIVER;
18 | import static com.wanjian.permission.OneKeyPerm.TIPS;
19 |
20 | /**
21 | * Created by wanjian on 2018/1/10.
22 | */
23 |
24 | public class WatchAuthorizationActivity extends AppCompatActivity {
25 | public static final String TAG = WatchAuthorizationActivity.class.getName();
26 | private final int REQUEST = 1;
27 | private String perm;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | Intent intent = getIntent();
33 | perm = intent.getStringExtra(ONE_KEY_PERM);
34 | request(intent.getStringExtra(TIPS));
35 | }
36 |
37 | private void request(String tips) {
38 | if (TextUtils.isEmpty(perm)) {
39 | finish();
40 | return;
41 | }
42 | try {
43 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
44 | intent.setData(Uri.fromParts("package", getPackageName(), null));
45 | startActivityForResult(intent, REQUEST);
46 |
47 | if (TextUtils.isEmpty(tips) == false) {
48 | Toast.makeText(this, tips, Toast.LENGTH_LONG).show();
49 | }
50 | } catch (Exception e) {
51 | onResult();
52 | }
53 | }
54 |
55 | @Override
56 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
57 | super.onActivityResult(requestCode, resultCode, data);
58 | // if (requestCode == REQUEST) {
59 | //
60 | // }
61 | onResult();
62 | }
63 |
64 |
65 | private void onResult() {
66 | IBinder receiver = getIntent().getExtras().getBinder(RECEIVER);
67 | int result = ContextCompat.checkSelfPermission(this, perm);
68 | Parcel parcel = Parcel.obtain();
69 | parcel.writeString(perm);
70 | parcel.writeInt(result);
71 | try {
72 | receiver.transact(0, parcel, Parcel.obtain(), IBinder.FLAG_ONEWAY);
73 | } catch (RemoteException e) {
74 | throw new RuntimeException(e);
75 | }
76 | finish();
77 | overridePendingTransition(0, 0);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/permission/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #0000
4 |
5 |
--------------------------------------------------------------------------------
/permission/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/permission/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':permission'
2 |
--------------------------------------------------------------------------------