权限
<uses-permission android:name="android.permission.INTERNET" />
动态获取读取内存权限
/**
* 检查app是否拥有存储权限,如果没有的话,提醒用户开启权限
*/
public void handlePermission() {
// 检查是否开启 Manifest.permission.xxx
// (xxx 为权限,根据自己需求添加)
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
} else {
// 请求权限
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}
多个权限同时获取
ActivityCompat.requestPermissions(this,new String[]{
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE
},1);