GitHub地址:https://github.com/yanzhenjie/AndPermission

这个库可以节省不少代码量和时间

使用示例如下

        findViewById(R.id.btnGetLocation).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AndPermission.with(HomeActivity.this).runtime().permission(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                        .onGranted(new Action<List<String>>() {
                            @Override
                            public void onAction(List<String> permissions) {
                                Log.d(TAG, "onAction(List<String>) called in onGranted, permissions: " + permissions);
                            }
                        })
                        .onDenied(new Action<List<String>>() {
                            @Override
                            public void onAction(List<String> data) {
                                Log.d(TAG, "onAction(List<String>) called in onDenied, data: " + data);
                            }
                        }).start();
            }
        });

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2021-10-10
  • 2021-07-26
  • 2021-12-21
  • 2021-09-24
  • 2018-12-16
相关资源
相似解决方案