Skip to content

Commit

Permalink
删除一些不合理的权限组,删除一些累赘代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HJQ committed Aug 21, 2018
1 parent 533cd4f commit 0b5aed1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 53 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
#### 集成步骤

dependencies {
implementation 'com.hjq:xxpermissions:3.6'
implementation 'com.hjq:xxpermissions:3.8'
}

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

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

@Override
Expand Down Expand Up @@ -51,7 +52,7 @@

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.hjq.permissions.demo"
minSdkVersion 14
targetSdkVersion 26
versionCode 36
versionName "3.6"
versionCode 38
versionName "3.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/hjq/permissions/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ protected void onCreate(Bundle savedInstanceState) {
public void requestPermission(View view) {
XXPermissions.with(this)
//.constantRequest() //可设置被拒绝后继续申请,直到用户授权或者永久拒绝
//.permission(Permission.REQUEST_INSTALL_PACKAGES, Permission.SYSTEM_ALERT_WINDOW) //支持请求安装权限和悬浮窗权限
.permission(Permission.Group.STORAGE, Permission.Group.CAMERA)
//.permission(Permission.REQUEST_INSTALL_PACKAGES) //支持8.0及以上请求安装权限
//.permission(Permission.SYSTEM_ALERT_WINDOW) //支持请求6.0及以上悬浮窗权限
.permission(Permission.Group.STORAGE) //不指定权限则自动获取清单中的危险权限
.request(new OnPermission() {

@Override
Expand All @@ -49,7 +50,7 @@ public void noPermission(List<String> denied, boolean quick) {
}

public void isHasPermission(View view) {
if (XXPermissions.isHasPermission(MainActivity.this, Permission.Group.STORAGE, Permission.Group.CAMERA)) {
if (XXPermissions.isHasPermission(MainActivity.this, Permission.Group.STORAGE)) {
Toast.makeText(MainActivity.this, "已经获取到权限,不需要再次申请了", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, "还没有获取到权限或者部分权限未授予", Toast.LENGTH_SHORT).show();
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 26
versionCode 36
versionName "3.6"
versionCode 38
versionName "3.8"
}
}

publish {
userOrg = 'getactivity'//填写bintray用户名,注意大小写
groupId = 'com.hjq'//定义的maven group id最终引用形式
artifactId = 'xxpermissions'//maven的artifact id
version = '3.6'//maven 上发布版本号
version = '3.8'//maven 上发布版本号
description = 'Android 6.0 permissions adaptation framework'//描述,自己定义
website = "https://github.com/getActivity/XXPermissions"//项目在github中的地址
}
Expand Down
37 changes: 2 additions & 35 deletions library/src/main/java/com/hjq/permissions/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
public final class Permission {

public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; // 8.0应用安装权限
public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; // 8.0及以上应用安装权限

public static final String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW"; // 6.0悬浮窗权限
public static final String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW"; // 6.0及以上悬浮窗权限

public static final String READ_CALENDAR = "android.permission.READ_CALENDAR"; // 读取日程提醒
public static final String WRITE_CALENDAR = "android.permission.WRITE_CALENDAR"; // 写入日程提醒
Expand Down Expand Up @@ -47,20 +47,11 @@ public final class Permission {

public static final class Group {

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

// 悬浮窗
public static final String[] WINDOW = new String[]{Permission.SYSTEM_ALERT_WINDOW};

// 日历
public static final String[] CALENDAR = new String[]{
Permission.READ_CALENDAR,
Permission.WRITE_CALENDAR};

// 摄像头
public static final String[] CAMERA = new String[]{Permission.CAMERA};

// 联系人
public static final String[] CONTACTS = new String[]{
Permission.READ_CONTACTS,
Expand All @@ -72,30 +63,6 @@ public static final class Group {
Permission.ACCESS_FINE_LOCATION,
Permission.ACCESS_COARSE_LOCATION};

// 话筒
public static final String[] MICROPHONE = new String[]{Permission.RECORD_AUDIO};

// 电话
public static final String[] PHONE = new String[]{
Permission.READ_PHONE_STATE,
Permission.CALL_PHONE,
Permission.READ_CALL_LOG,
Permission.WRITE_CALL_LOG,
Permission.ADD_VOICEMAIL,
Permission.USE_SIP,
Permission.PROCESS_OUTGOING_CALLS};

// 传感器
public static final String[] SENSORS = new String[]{Permission.BODY_SENSORS};

// 短信
public static final String[] SMS = new String[]{
Permission.SEND_SMS,
Permission.RECEIVE_SMS,
Permission.READ_SMS,
Permission.RECEIVE_WAP_PUSH,
Permission.RECEIVE_MMS};

// 存储
public static final String[] STORAGE = new String[]{
Permission.READ_EXTERNAL_STORAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class PermissionFragment extends Fragment {
private static final String REQUEST_CONSTANT = "request_constant";

private final static SparseArray<OnPermission> sContainer = new SparseArray<>();
private static long sRequestTime;//请求的时间

public static PermissionFragment newInstant(ArrayList<String> permissions, boolean constant) {
PermissionFragment fragment = new PermissionFragment();
Expand Down Expand Up @@ -62,6 +61,8 @@ public void onActivityCreated(Bundle savedInstanceState) {

ArrayList<String> permissions = getArguments().getStringArrayList(PERMISSION_GROUP);

if (permissions == null) return;

if ((permissions.contains(Permission.REQUEST_INSTALL_PACKAGES) && !PermissionUtils.isHasInstallPermission(getActivity()))
|| (permissions.contains(Permission.SYSTEM_ALERT_WINDOW) && !PermissionUtils.isHasOverlaysPermission(getActivity()))) {

Expand All @@ -77,13 +78,8 @@ public void onActivityCreated(Bundle savedInstanceState) {
startActivityForResult(intent, getArguments().getInt(REQUEST_CODE));
}

//记录本次申请时间
sRequestTime = System.currentTimeMillis();

} else {
requestPermission();
//记录本次申请时间
sRequestTime = System.currentTimeMillis();
}
}

Expand Down

0 comments on commit 0b5aed1

Please sign in to comment.