【问题标题】:Store file in Huawei Drive Kit在华为Drive Kit中存储文件
【发布时间】:2021-04-02 01:17:25
【问题描述】:

我正在尝试编写一个简单的 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/

【问题讨论】:

    标签: huawei-mobile-services huawei-developers


    【解决方案1】:

    最有可能是权限致命错误,我们应该尝试启用权限,如果已经被拒绝,请转到手机设置并启用阻止权限。和内部代码例如:

    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); }
    

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 2020-04-08
      相关资源
      最近更新 更多