哥们点个赞再走呀
制作不容易,条件允许情况下,打赏一下,谢谢
项目build.gradle
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
加入作者的依赖,其中用户名就是作者的微信
implementation 'com.github.nihaoxj123:rCode:1.1.4'
使用方法
在AndroidManifest注册需要的权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
public class MainActivity extends AppCompatActivity {
private PermissionUtils permissionUtils;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
permissionUtils = new PermissionUtils(this,1001,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE);
permissionUtils.checkPermission(new PermissionUtils.OnPermissionCallback() {
@Override
public void onGranted(int requestCode, String permission) {
Log.d("MainActivity", "允许授权:" + permission);
}
@Override
public void onDenied(int requestCode, String permission) {
Log.d("MainActivity", "拒接授权:" + permission);
}
@Override
public void onFinish(int requestCode, boolean grantedAll) {
if (grantedAll){
Toast.makeText(MainActivity.this, "已授权所有", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, "没有全部授权", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
permissionUtils.onRequestPermissionsResult(requestCode,permissions,grantResults);
}
}
- 制作不容易,条件允许情况下,打赏一下,谢谢