Skip to content

Commit f1a28cb

Browse files
author
hupei
committed
增加 M 版本检测
1 parent f989d43 commit f1a28cb

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#使用Gradle构建时添加一下依赖即可:
1212
```javascript
13-
compile 'com.mylhyl:acp:1.0.2'
13+
compile 'com.mylhyl:acp:1.1.2'
1414
```
1515

1616
# 使用说明
@@ -50,3 +50,5 @@ compile 'com.mylhyl:acp:1.0.2'
5050
> 1.0.1 修改 minSdkVersion 14
5151
5252
> 1.0.2 修复申请的权限不在`AndroidManifest.xml`配置文件时,中仍然显示`RationalMessage`对话框的问题
53+
54+
> 1.1.2 增加`M`版本检测

acp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def siteUrl = 'https://github.com/mylhyl/AndroidAcp'
2626
def gitUrl = 'https://github.com/mylhyl/AndroidAcp.git'
2727

2828
group = "com.mylhyl"
29-
version = "1.0.2"
29+
version = "1.1.2"
3030

3131
install {
3232
repositories.mavenInstaller {

acp/src/main/java/com/mylhyl/acp/AcpManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.pm.PackageInfo;
1010
import android.content.pm.PackageManager;
1111
import android.net.Uri;
12+
import android.os.Build;
1213
import android.provider.Settings;
1314

1415
import java.util.HashSet;
@@ -62,6 +63,11 @@ synchronized void request(AcpOptions options, AcpListener acpListener) {
6263

6364
private synchronized void checkSelfPermission() {
6465
mDeniedPermissions.clear();
66+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
67+
mCallback.onGranted();
68+
onDestroy();
69+
return;
70+
}
6571
String[] permissions = mOptions.getPermissions();
6672
for (String permission : permissions) {
6773
//检查申请的权限是否在 AndroidManifest.xml 中

acp/src/main/java/com/mylhyl/acp/AcpService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.content.pm.PackageInfo;
6+
import android.content.pm.PackageManager;
7+
import android.os.Build;
58
import android.support.v4.app.ActivityCompat;
69
import android.support.v4.content.ContextCompat;
10+
import android.support.v4.content.PermissionChecker;
711

812
/**
913
* Created by hupei on 2016/4/26.
@@ -17,6 +21,20 @@ class AcpService {
1721
* @return
1822
*/
1923
int checkSelfPermission(Context context, String permission) {
24+
try {
25+
final PackageInfo info = context.getPackageManager().getPackageInfo(
26+
context.getPackageName(), 0);
27+
int targetSdkVersion = info.applicationInfo.targetSdkVersion;
28+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
29+
if (targetSdkVersion >= Build.VERSION_CODES.M) {
30+
return ContextCompat.checkSelfPermission(context, permission);
31+
} else {
32+
return PermissionChecker.checkSelfPermission(context, permission);
33+
}
34+
}
35+
} catch (PackageManager.NameNotFoundException e) {
36+
e.printStackTrace();
37+
}
2038
return ContextCompat.checkSelfPermission(context, permission);
2139
}
2240

preview/img0.png

-197 KB
Binary file not shown.

preview/img1.png

-172 KB
Binary file not shown.

preview/sample-debug.apk

71.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)