Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzzchehe authored Dec 21, 2020
1 parent 0d0e736 commit 7fee62e
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Step 2. Add the dependency
}


https://www.jianshu.com/p/3ec8fd6c4754

可以调用的方案有两种:
第一种:
Activity 中如何调用?
1、Activity 实现回调接口,并重写对应回调函数:
如:
1、Activity 实现回调接口,并重写对应回调函数,如:
public class MainActivity extends AppCompatActivity implements ZyzzcPermissionUtils.CallBack {
@Override
public void grantAll() {
Expand All @@ -46,23 +45,51 @@ perList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
zyzzcPermissionUtils.request(perList, reqCode, this);

3、重写onRequestPermissionsResult函数
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == reqCode) {
AtomicBoolean grantAll = new AtomicBoolean(true);
//遍历每一个授权结果
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
grantAll.set(false);
Toast.makeText(this, permissions[i] + "未授权", Toast.LENGTH_SHORT).show();
break;
}
}
if (grantAll.get()) {
grantAll();
} else {
denied();
}
}
}

第二种:
public class MyApp extends Application {
static List<String> permissionList = new ArrayList<>();

static {
permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
permissionList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == reqCode) {
AtomicBoolean grantAll = new AtomicBoolean(true);
//遍历每一个授权结果
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
grantAll.set(false);
Toast.makeText(this, permissions[i] + "未授权", Toast.LENGTH_SHORT).show();
break;
public void onCreate() {
super.onCreate();
if(Build.VERSION.SDK_INT > 23) {
PermissionsUtil.requestPermission(getApplicationContext(), new PermissionListener() {
@Override
public void permissionGranted(@NonNull String[] permissions) {
Log.d("yazhou", "permission allow");
}
}
if (grantAll.get()) {
grantAll();
} else {
denied();
}

@Override
public void permissionDenied(@NonNull String[] permissions) {
Log.d("yazhou", "permission deny");
}
}, permissionList.toArray(new String[]{}));
}
}
}

0 comments on commit 7fee62e

Please sign in to comment.