huawei-mobile-services - 将文件存储在华为 Drive Kit 中
问题描述
我正在尝试编写一个简单的 Android 应用程序,将文件存储在华为云端硬盘中。但是程序在尝试访问驱动器时会立即崩溃。好像应该很容易集成,为什么会有这么大的错误?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_MEDIA_STORAGE"
tools:ignore="ProtectedPermissions" />
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(PERMISSIONS_STORAGE, 1);
}
https://developer.huawei.com/consumer/en/hms/huawei-drivekit/
解决方案
一件事最有可能是权限致命错误,我们应该尝试启用权限,如果它已经被拒绝,请转到手机设置并启用阻止权限。和内部代码例如:
if (ContextCompat.checkSelfPermission( CONTEXT, Manifest.permission.REQUESTED_PERMISSION) == PackageManager.PERMISSION_GRANTED)
{ // You can use the API that requires the permission. performAction(...); }
else if (shouldShowRequestPermissionRationale(...)) { // In an educational UI, explain to the user why your app requires this // permission for a specific feature to behave as expected. In this UI, // include a "cancel" or "no thanks" button that allows the user to // continue using your app without granting the permission. showInContextUI(...); }
else { // You can directly ask for the permission. // The registered ActivityResultCallback gets the result of this request. requestPermissionLauncher.launch( Manifest.permission.REQUESTED_PERMISSION); }
推荐阅读
- java - 如何对对象的特定类型方法使用 Java 反射
- python - 从python中的文本文件中提取值
- python - Botocore 错误:HTTP 客户端引发未处理的异常:sys.meta_path 必须是导入挂钩列表
- wxwidgets - wxScrolled.SetScale() 有什么作用?
- image - 如何在颤动中重新着色图像?
- python - 如何在python中将单引号传递给json字符串?
- python - 如何使用 python 清理 url
- sql - SQL Count Distinct 返回一个额外的计数
- android - 使用android room时即使没有更新数据也会更新
- php - 使用 SimpleXMLParser 获取嵌套节点值