赞
踩
适配Android X使用(建议使用):
- dependencies {
- implementation 'com.qw:soulpermission:1.2.2_x'
- }
- 如果你的应用
没有适配Android X使用:
- dependencies {
- implementation 'com.qw:soulpermission:1.2.2'
- }
基本用法:
- SoulPermission.getInstance().checkAndRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION,
- //if you want do noting or no need all the callbacks you may use SimplePermissionAdapter instead
- new CheckRequestPermissionListener() {
- @Override
- public void onPermissionOk(Permission permission) {
- Toast.makeText(ApiGuideActivity.this, permission.toString() +
- "\n is ok , you can do your operations", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionDenied(Permission permission) {
- Toast.makeText(ApiGuideActivity.this, permission.toString() +
- " \n is refused you can not do next things", Toast.LENGTH_SHORT).show();
- }
- });
- SoulPermission.getInstance().checkAndRequestPermissions(
- Permissions.build(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE),
- //if you want do noting or no need all the callbacks you may use SimplePermissionsAdapter instead
- new CheckRequestPermissionsListener() {
- @Override
- public void onAllPermissionOk(Permission[] allPermissions) {
- Toast.makeText(ApiGuideActivity.this, allPermissions.length + "permissions is ok" +
- " \n you can do your operations", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionDenied(Permission[] refusedPermissions) {
- Toast.makeText(ApiGuideActivity.this, refusedPermissions[0].toString() +
- " \n is refused you can not do next things", Toast.LENGTH_SHORT).show();
- }
- });
- SoulPermission.getInstance().checkAndRequestPermission(Manifest.permission.READ_CONTACTS,
- new CheckRequestPermissionListener() {
- @Override
- public void onPermissionOk(Permission permission) {
- Toast.makeText(ApiGuideActivity.this, permission.toString() +
- "\n is ok , you can do your operations", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionDenied(Permission permission) {
- // see CheckPermissionWithRationaleAdapter
- if (permission.shouldRationale()) {
- Toast.makeText(ApiGuideActivity.this, permission.toString() +
- " \n you should show a explain for user then retry ", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(ApiGuideActivity.this, permission.toString() +
- " \n is refused you can not do next things", Toast.LENGTH_SHORT).show();
- }
- }
- });
- //you can also use checkPermissions() for a series of permissions
- Permission checkResult = SoulPermission.getInstance().checkSinglePermission(Manifest.permission.ACCESS_FINE_LOCATION);
boolean checkResult = SoulPermission.getInstance().checkSpecialPermission(Special.NOTIFICATION);
- //if you want do noting or no need all the callbacks you may use SimpleSpecialPermissionAdapter instead
- SoulPermission.getInstance().checkAndRequestPermission(Special.UNKNOWN_APP_SOURCES, new SpecialPermissionListener() {
- @Override
- public void onGranted(Special permission) {
- Toast.makeText(ApiGuideActivity.this, "install unKnown app is enable now", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onDenied(Special permission) {
- Toast.makeText(ApiGuideActivity.this, "install unKnown app is disable yet", Toast.LENGTH_SHORT).show();
- }
- });
- SoulPermission.getInstance().goApplicationSettings(new GoAppDetailCallBack() {
- @Override
- public void onBackFromAppDetail(Intent data) {
- //if you need to know when back from app detail
- Utils.showMessage(view, "back from go appDetail");
- }
- });
SoulPermission.skipOldRom(true);
SoulPermission.setDebug(true);
注意事项:
- //invoke init in your application when auto init failed
- public class SimpleApplication extends Application {
- @Override
- public void onCreate() {
- super.onCreate();
- //no necessary
- SoulPermission.init(this);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。