0
votes

I am trying to write a simple Android app that stores a file in Huawei Drive. But program crashes immediately when trying to access drive. Seems it is supposed to be easy integration, why does it have such a big error?

<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/

1

1 Answers

0
votes

One thing most likely is permission fatal error, we should try to enable permission and if it is already denied, go to phone setting and enable permission from blocking. and inside code for example:

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