Skip to content

Commit 6706322

Browse files
committed
compile
1 parent 535bde2 commit 6706322

File tree

8 files changed

+89
-53
lines changed

8 files changed

+89
-53
lines changed

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 26
4+
compileSdkVersion 33
55
defaultConfig {
66
applicationId "com.wanjian.permission.demo"
7-
minSdkVersion 14
8-
targetSdkVersion 26
7+
minSdkVersion 18
8+
targetSdkVersion 33
99
versionCode 1
1010
versionName "1.0"
1111
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
android:roundIcon="@mipmap/ic_launcher_round"
1515
android:supportsRtl="true"
1616
android:theme="@style/AppTheme">
17-
<activity android:name=".MainActivity">
17+
<activity android:name=".MainActivity"
18+
android:exported="true">
1819
<intent-filter>
1920
<action android:name="android.intent.action.MAIN" />
2021

app/src/main/java/com/wanjian/permission/demo/MainActivity.java

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Context;
66
import android.content.Intent;
77
import android.os.Bundle;
8+
import android.os.Handler;
89
import android.support.v7.app.AppCompatActivity;
910
import android.view.View;
1011
import android.widget.TextView;
@@ -15,44 +16,57 @@
1516

1617
public class MainActivity extends AppCompatActivity {
1718

19+
1820
@Override
1921
protected void onCreate(Bundle savedInstanceState) {
2022
super.onCreate(savedInstanceState);
2123
setContentView(R.layout.activity_main);
22-
findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
23-
@Override
24-
public void onClick(View v) {
25-
OneKeyPerm.request(getApplication(), Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
26-
@Override
27-
public void onPermResult(String perm, boolean isGrant) {
28-
Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
29-
}
30-
},true);
31-
}
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);
3231
});
3332

34-
findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
35-
@Override
36-
public void onClick(View v) {
37-
OneKeyPerm.request(getApplication(), Manifest.permission.READ_EXTERNAL_STORAGE, "您需要允许读取文件权限,否则无法查看图片", new OneKeyPerm.OnPermResultListener() {
38-
@Override
39-
public void onPermResult(String perm, boolean isGrant) {
40-
Toast.makeText(MainActivity.this, "请求读取权限 " + isGrant, Toast.LENGTH_SHORT).show();
41-
}
42-
},true);
43-
}
33+
findViewById(R.id.btn4).setOnClickListener(v -> {
34+
showHomeScreen();
35+
new Handler().postDelayed(() -> requestStoragePermission(), 2000);
4436
});
4537

46-
findViewById(R.id.newAct).setOnClickListener(new View.OnClickListener() {
47-
@Override
48-
public void onClick(View v) {
49-
startActivity(new Intent(getApplicationContext(), SecondAct.class));
50-
}
38+
findViewById(R.id.btn5).setOnClickListener(v -> {
39+
finish();
40+
new Handler().postDelayed(() -> requestCameraPermission(), 2000);
5141
});
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)));
5250
((TextView) findViewById(R.id.tv)).setText(processName() + " " + android.os.Process.myPid());
5351

5452
}
5553

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+
5670
private String processName() {
5771
int pid = android.os.Process.myPid();
5872
String processName;
@@ -65,4 +79,13 @@ private String processName() {
6579
}
6680
return null;
6781
}
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+
}
6891
}

app/src/main/res/layout/activity_main.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@
2929
android:layout_marginTop="10dp"
3030
android:text="主进程 请求文件读取权限" />
3131

32+
<Button
33+
android:id="@+id/btn3"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:layout_marginTop="10dp"
37+
android:text="主进程 后台 请求相机权限" />
38+
39+
<Button
40+
android:id="@+id/btn4"
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"
43+
android:layout_marginTop="10dp"
44+
android:text="主进程 后台 请求文件读取权限" />
45+
46+
<Button
47+
android:id="@+id/btn5"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:layout_marginTop="10dp"
51+
android:text="主进程 销毁后 请求相机权限" />
52+
53+
<Button
54+
android:id="@+id/btn6"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:layout_marginTop="10dp"
58+
android:text="主进程 销毁后 请求文件读取权限" />
59+
60+
3261
<Button
3362
android:id="@+id/newAct"
3463
android:layout_width="wrap_content"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.6.1'
10+
classpath 'com.android.tools.build:gradle:7.4.2'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Aug 10 21:27:31 CST 2020
1+
#Wed May 07 19:04:44 CST 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

permission/build.gradle

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
apply plugin: 'com.android.library'
2-
apply plugin: 'com.novoda.bintray-release'//添加
32
android {
4-
compileSdkVersion 26
3+
compileSdkVersion 33
54

65
defaultConfig {
7-
minSdkVersion 14
8-
targetSdkVersion 26
6+
minSdkVersion 18
7+
targetSdkVersion 33
98
versionCode 1
109
versionName "1.0"
1110

@@ -32,23 +31,8 @@ buildscript {
3231
google()
3332
}
3433
dependencies {
35-
classpath 'com.android.tools.build:gradle:3.6.1'
36-
classpath 'com.novoda:bintray-release:0.8.0'
34+
classpath 'com.android.tools.build:gradle:7.4.2'
3735
}
3836
}
3937

4038

41-
42-
//添加 先执行 generatePomFileForReleasePublication和publishReleasePublicationToMabenLocal,再执行bintrayUpload。在publishing下
43-
publish {
44-
groupId = 'com.wanjian'
45-
artifactId = 'onekeyperm'
46-
publishVersion = '0.0.3'
47-
desc = '一键申请Android权限,不依赖任何业务Activity。小巧、简约、强悍'
48-
website = 'https://github.com/android-notes/OneKeyPerm'
49-
50-
bintrayUser = 'wanjian' // 账户名
51-
bintrayKey = '...' // 就是API key
52-
dryRun = false
53-
54-
}

0 commit comments

Comments
 (0)