Score
0
Watch 24 Star 66 Fork 19

幺鹿 / lib-android-PermissionHelperAndroid

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
封装 Android M 的权限申请 android runtime permission acquire spread retract

Clone or download
README.md 3.97 KB
Copy Edit Web IDE Raw Blame History
幺鹿 authored 2016-07-05 22:33 . Update README.md

我的其他仓库推荐

分类(lib-android) -描述- -仓库链接-
LoadingLayout Android 业务开发常用的 loadinglayout 用于封装加载过程中,加载完成&有数据,加载完成&无数据,加载错误的情况。 https://git.oschina.net/alpha4/lib-android-LoadingLayout
VerifyCollect Android 业务开发常用的 verify-collect 用于封装 验证 过程。 https://git.oschina.net/alpha4/lib-android-VerifyCollect
PermissionHelper Android M 权限申请 https://git.oschina.net/alpha4/lib-android-PermissionHelper
Social Android 第三方社会化分享、登录 https://git.oschina.net/alpha4/lib-android-Social
分类(完整开源项目) -描述- -仓库链接-
Tutur(音乐家教) 音乐家教B&C端业务实现 https://git.oschina.net/alpha4/Tutor

Android M 权限申请

[http://developer.android.com/training/permissions/index.html] [http://developer.android.com/guide/topics/security/permissions.html]

有任何建议或反馈 请联系: chenjunqi.china@gmail.com

欢迎大家加入android 开源项目群(369194705), 有合适的项目大家一起 fork;

你可能希望了解这些adb shell命令:

root@generic_x86:/ # pm list permissions 
root@generic_x86:/ $ pm revoke com.bookbuf.android android.permission.READ_CONTACTS
root@generic_x86:/ $ pm grant com.bookbuf.android android.permission.READ_CONTACTS

准备待请求/检查的权限


	/*示例权限*/
	public PermEntityCompat[] exampleSinglePerm () {
		PermEntityCompat perm = new PermEntityCompat (Manifest.permission.READ_CONTACTS, "联系人权限", "读取联系人权限是为了xxxxxx");
		return new PermEntityCompat[]{perm};
	}

	public PermEntityCompat[] exampleGroupPerms () {
		PermEntityCompat[] perms = new PermEntityCompat[]{
				new PermEntityCompat (Manifest.permission.READ_CONTACTS, "联系人权限", "读取联系人权限是为了xxxxxx"),
				new PermEntityCompat (Manifest.permission.READ_CALENDAR, "日历权限", "读取日历权限是为了 xxxxxx"),
				new PermEntityCompat (Manifest.permission.READ_SMS, "短信权限", " 读取短信权限是为了 xxxxxx")
		};
		return perms;
	}

注册回调事件

	
	public OnRequestPermissionsResultCallback callback () {
		if (callback != null) return callback;
		callback = new OnRequestPermissionsResultCallback<PermEntityCompat> () {
			@Override
			public void onGranted (PermEntityCompat... permission) {
				String[] perms = PermUtil.permissions (permission);
				Log.e (TAG, "onGranted : " + Arrays.toString (perms));
			}

			@Override
			public void onDenied (PermEntityCompat... permission) {
				String[] perms = PermUtil.permissions (permission);
				Log.e (TAG, "onDenied : " + Arrays.toString (perms));
			}

			@Override
			public void onChecked (boolean isGranted, PermEntityCompat... permission) {
				String[] perms = PermUtil.permissions (permission);
				Log.e (TAG, "onChecked : " + Arrays.toString (perms) + ":权限检查:" + isGranted);
			}
		};
		return callback;
	}
	

重写ActivityonRequestPermissionsResult方法:


	@Override
	public void onRequestPermissionsResult (int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
		super.onRequestPermissionsResult (requestCode, permissions, grantResults);
		PermDelegateCompat.onRequestPermissionsResult (requestCode, permissions, grantResults);
	}

发起权限申请


	PermDelegateCompat.Debug.register (this, callback ());
	// ...
	PermDelegateCompat.Client.requestIfNotAcquirePermission (exampleGroupPerms ());
	// ...
	PermDelegateCompat.Debug.unregister (this, callback ());

非常感谢 项目androidPermissionHelper给予的一些参考;

Comment ( 0 )

Sign in for post a comment

Android
1
https://gitee.com/alpha4/lib-android-PermissionHelper.git
git@gitee.com:alpha4/lib-android-PermissionHelper.git
alpha4
lib-android-PermissionHelper
lib-android-PermissionHelper
master

Search