1、需要申请手机读写的权限
AndroidMani.xml里面配置权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
我们一般采用RxPermission来申请权限
RxPermissions(this).requestEachCombined(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
).subscribe {
when {
it.granted -> {
}
it.shouldShowRequestPermissionRationale -> {
}
else -> {
}
}
}