//权限 implementation 'pub.devrel:easypermissions:1.0.1'
1 activity实现callback接口
public class SplashActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks
2 activity请求权限
EasyPermissions.requestPermissions(this,"请求安装应用权限",0,Manifest.permission.REQUEST_INSTALL_PACKAGES);
3 权限回调
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
if (perms.size() >0 && Manifest.permission.REQUEST_INSTALL_PACKAGES.equals(perms.get(0))){
requestPermissions();
}else {
updateManager.installApk();
}
}
private int GET_UNKNOWN_APP_SOURCES = 100;
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
if (perms.size() >0 && Manifest.permission.REQUEST_INSTALL_PACKAGES.equals(perms.get(0))){
// 引导用户手动开启安装权限
ToastUtils.showToast(getApplicationContext(),"申请安装应用权限失败,\n请选择村知书打开安装权限");
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);
}else {
requestPermissions();
}
}