Skip to content

Commit

Permalink
支持请求安装和悬浮窗权限和新增无限回调功能
Browse files Browse the repository at this point in the history
  • Loading branch information
HJQ committed Aug 6, 2018
1 parent 759760d commit 41e2e41
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 194 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#### 集成步骤

dependencies {
compile 'com.hjq:xxpermissions:2.2'
implementation 'com.hjq:xxpermissions:3.0'
}

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

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

Expand Down Expand Up @@ -50,6 +51,8 @@

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

* 支持请求6.0以上的悬浮窗权限以及8.0以上的安装权限

* 本框架不依赖AppCompatSupport库,兼容Eclipse和Studio

#### 混淆规则
Expand Down
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.hjq.permissions.demo"
minSdkVersion 11
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionCode 30
versionName "3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -20,7 +20,7 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
compile 'com.android.support:appcompat-v7:25+'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':library')
implementation 'com.android.support:appcompat-v7:26.1.0'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
android:icon="@mipmap/ic_launcher"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/hjq/permissions/demo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hjq.permissions.demo;

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

@Override
Expand Down
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ allprojects {
google()
maven {url "https://jitpack.io"}
}

//解决app:mockableAndroidJar错误的问题
gradle.taskGraph.whenReady {
tasks.each { task ->
if (task.name.equals('mockableAndroidJar')) {
task.enabled = false
}
}
}
}

task clean(type: Delete) {
Expand Down
9 changes: 4 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 26
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 20
versionName "2.2"
targetSdkVersion 26
versionCode 30
versionName "3.0"
}
}

publish {
userOrg = 'getactivity'//填写bintray用户名,注意大小写
groupId = 'com.hjq'//定义的maven group id最终引用形式
artifactId = 'xxpermissions'//maven的artifact id
version = '2.2'//maven 上发布版本号
version = '3.0'//maven 上发布版本号
description = 'Android 6.0 permissions adaptation framework'//描述,自己定义
website = "https://github.com/getActivity/XXPermissions"//项目在github中的地址
}
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/com/hjq/permissions/OnPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public interface OnPermission {
/**
* 有权限被授予时回调
*
* @param granted 请求成功的权限组
* @param isAll 是否全部授予了
* @param granted 请求成功的权限组
* @param isAll 是否全部授予了
*/
void hasPermission(List<String> granted, boolean isAll);

/**
* 有权限被拒绝授予时回调
*
* @param denied 请求失败的权限组
* @param quick 是否被系统自动拒绝了
* @param denied 请求失败的权限组
* @param quick 是否被系统自动拒绝了
*/
void noPermission(List<String> denied, boolean quick);
}
70 changes: 0 additions & 70 deletions library/src/main/java/com/hjq/permissions/OverlaySettingPage.java

This file was deleted.

4 changes: 4 additions & 0 deletions library/src/main/java/com/hjq/permissions/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Permission {

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

public static final String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW";

public static final class Group {

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

public static final String[] INSTALL = new String[]{Permission.REQUEST_INSTALL_PACKAGES};

public static final String[] WINDOW = new String[]{Permission.SYSTEM_ALERT_WINDOW};
}
}
Loading

0 comments on commit 41e2e41

Please sign in to comment.