Skip to content

Commit 41e2e41

Browse files
author
HJQ
committed
支持请求安装和悬浮窗权限和新增无限回调功能
1 parent 759760d commit 41e2e41

File tree

13 files changed

+132
-194
lines changed

13 files changed

+132
-194
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#### 集成步骤
88

99
dependencies {
10-
compile 'com.hjq:xxpermissions:2.2'
10+
implementation 'com.hjq:xxpermissions:3.0'
1111
}
1212

1313
#### 一句代码搞定权限请求,从未如此简单
1414

1515
XXPermissions.with(this)
1616
//.constantRequest() //可设置被拒绝后继续申请,直到用户授权或者永久拒绝
17+
//.permission(Permission.REQUEST_INSTALL_PACKAGES, Permission.SYSTEM_ALERT_WINDOW) //支持请求安装权限和悬浮窗权限
1718
.permission(Permission.Group.STORAGE) //支持多个权限组进行请求,不指定则默以清单文件中的危险权限进行请求
1819
.request(new OnPermission() {
1920

@@ -50,6 +51,8 @@
5051

5152
* 可设置被拒绝后继续申请,直到用户授权或者永久拒绝
5253

54+
* 支持请求6.0以上的悬浮窗权限以及8.0以上的安装权限
55+
5356
* 本框架不依赖AppCompatSupport库,兼容Eclipse和Studio
5457

5558
#### 混淆规则

app/build.gradle

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

33
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.3"
4+
compileSdkVersion 26
5+
buildToolsVersion "27.0.3"
66
defaultConfig {
77
applicationId "com.hjq.permissions.demo"
8-
minSdkVersion 11
8+
minSdkVersion 14
99
targetSdkVersion 26
10-
versionCode 1
11-
versionName "1.0"
10+
versionCode 30
11+
versionName "3.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {
@@ -20,7 +20,7 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(include: ['*.jar'], dir: 'libs')
24-
compile project(':library')
25-
compile 'com.android.support:appcompat-v7:25+'
26-
}
23+
implementation fileTree(include: ['*.jar'], dir: 'libs')
24+
implementation project(':library')
25+
implementation 'com.android.support:appcompat-v7:26.1.0'
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<uses-permission android:name="android.permission.CAMERA" />
99

1010
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
11+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
1112

1213
<application
1314
android:icon="@mipmap/ic_launcher"

app/src/main/java/com/hjq/permissions/demo/MainActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hjq.permissions.demo;
22

3-
import android.Manifest;
43
import android.os.Bundle;
54
import android.support.v7.app.AppCompatActivity;
65
import android.view.View;
@@ -23,8 +22,8 @@ protected void onCreate(Bundle savedInstanceState) {
2322
public void requestPermission(View view) {
2423
XXPermissions.with(this)
2524
//.constantRequest() //可设置被拒绝后继续申请,直到用户授权或者永久拒绝
26-
// .permission(Permission.Group.STORAGE, Permission.Group.CAMERA)
27-
.permission(Permission.REQUEST_INSTALL_PACKAGES, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)
25+
//.permission(Permission.REQUEST_INSTALL_PACKAGES, Permission.SYSTEM_ALERT_WINDOW) //支持请求安装权限和悬浮窗权限
26+
.permission(Permission.Group.STORAGE, Permission.Group.CAMERA)
2827
.request(new OnPermission() {
2928

3029
@Override

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ allprojects {
1717
google()
1818
maven {url "https://jitpack.io"}
1919
}
20+
21+
//解决app:mockableAndroidJar错误的问题
22+
gradle.taskGraph.whenReady {
23+
tasks.each { task ->
24+
if (task.name.equals('mockableAndroidJar')) {
25+
task.enabled = false
26+
}
27+
}
28+
}
2029
}
2130

2231
task clean(type: Delete) {

library/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ apply plugin: 'com.novoda.bintray-release'
44

55
android {
66
compileSdkVersion 26
7-
buildToolsVersion "25.0.3"
87

98
defaultConfig {
109
minSdkVersion 11
11-
targetSdkVersion 23
12-
versionCode 20
13-
versionName "2.2"
10+
targetSdkVersion 26
11+
versionCode 30
12+
versionName "3.0"
1413
}
1514
}
1615

1716
publish {
1817
userOrg = 'getactivity'//填写bintray用户名,注意大小写
1918
groupId = 'com.hjq'//定义的maven group id最终引用形式
2019
artifactId = 'xxpermissions'//maven的artifact id
21-
version = '2.2'//maven 上发布版本号
20+
version = '3.0'//maven 上发布版本号
2221
description = 'Android 6.0 permissions adaptation framework'//描述,自己定义
2322
website = "https://github.com/getActivity/XXPermissions"//项目在github中的地址
2423
}

library/src/main/java/com/hjq/permissions/OnPermission.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ public interface OnPermission {
1010
/**
1111
* 有权限被授予时回调
1212
*
13-
* @param granted 请求成功的权限组
14-
* @param isAll 是否全部授予了
13+
* @param granted 请求成功的权限组
14+
* @param isAll 是否全部授予了
1515
*/
1616
void hasPermission(List<String> granted, boolean isAll);
1717

1818
/**
1919
* 有权限被拒绝授予时回调
2020
*
21-
* @param denied 请求失败的权限组
22-
* @param quick 是否被系统自动拒绝了
21+
* @param denied 请求失败的权限组
22+
* @param quick 是否被系统自动拒绝了
2323
*/
2424
void noPermission(List<String> denied, boolean quick);
2525
}

library/src/main/java/com/hjq/permissions/OverlaySettingPage.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

library/src/main/java/com/hjq/permissions/Permission.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public final class Permission {
4040

4141
public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES";
4242

43+
public static final String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW";
44+
4345
public static final class Group {
4446

4547
public static final String[] CALENDAR = new String[]{
@@ -82,5 +84,7 @@ public static final class Group {
8284
Permission.WRITE_EXTERNAL_STORAGE};
8385

8486
public static final String[] INSTALL = new String[]{Permission.REQUEST_INSTALL_PACKAGES};
87+
88+
public static final String[] WINDOW = new String[]{Permission.SYSTEM_ALERT_WINDOW};
8589
}
8690
}

0 commit comments

Comments
 (0)