Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTA Event Status] Permission not granted error (Harmony OS 3.0.0) #118

Open
ogak-github opened this issue Jul 5, 2024 · 7 comments
Open

Comments

@ogak-github
Copy link

I got the error permission not granted before starting the OtaUpdate()

I tried in Emulator android API 34 and other different brand smartphone with Android 14 no issues, but with Harmony OS 3.0.0 permission not granted.

D/FLUTTER OTA(29480): STREAM CLOSED D/FLUTTER OTA(29480): STREAM OPENED D/FLUTTER OTA(29480): REQUEST PERMISSIONS RESULT RECEIVED E/FLUTTER OTA(29480): ERROR: Permission not granted

@rafadompas
Copy link

I have the same problem. Permission not granted with xiaomi and huawai.

Any idea?

@ogak-github
Copy link
Author

I forgot why this issue appear,
Try check storage permission status before starting ota update

 Future<void> requestPermissions() async {
    var status = await Permission.storage.status;
    if (!status.isGranted) {
      await Permission.storage.request();
    }
  }

Let me know if the issue fixed. Then I mark this issue as closed.

@rafadompas
Copy link

I do it but send the same error

@rafadompas
Copy link

Hello, I continue with the error. Any idea how to solve it? Thank you so much!!

@ogak-github
Copy link
Author

Check your manifest..

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    
    <!-- Install Package Permission -->
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    
     <provider
            android:name="sk.fourq.otaupdate.OtaUpdateFileProvider"
            android:authorities="${applicationId}.ota_update_provider"
            android:exported="false"
            android:grantUriPermissions="true">

@rafadompas
Copy link

I have the same problem

My manifest is this:

<!-- Permisos -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- Queries -->
<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="mailto" />
    </intent>
</queries>

<!-- Application -->
<application
    android:allowBackup="false"
    android:name="${applicationName}" 
    android:label="rafa"
    android:icon="@mipmap/ic_launcher"
    android:networkSecurityConfig="@xml/network_security_config">

    <!-- Actividad principal -->
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme"
        />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <!-- Receptores -->
    <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />
    <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
    <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
        </intent-filter>
    </receiver>

    <!-- UCrop Activity -->
    <activity
      android:name="com.yalantis.ucrop.UCropActivity"
      android:screenOrientation="portrait"
      android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

    <!-- Flutter meta-data -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />

    <!-- Proveedor OTA -->
    <provider
        android:name="sk.fourq.otaupdate.OtaUpdateFileProvider"
        android:authorities="${applicationId}.ota_update_provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
    </provider>
</application>

@ogak-github
Copy link
Author

I see.. this should fix your problem
Below, I am using permission handler package..
for Android 13 above use Permission.photos and videos
for below Android 13 use storage

Future<bool> _requestStoragePermission() async {
    List<Permission> permissions;
    permissions = [
      Permission.storage,
      Permission.photos,
      Permission.videos,
    ];
    final status = await permissions.request();
    final storagePermissions = [
      Permission.storage,
      Permission.photos,
      Permission.videos
    ];
    for (var item in status.entries) {
      log(status.entries.toSet().toList().toString());
      //log(status.entries.toSet().toList().toString(), name: "ALL BL PERMISSIONS");
      if (storagePermissions.contains(item.key)) {
        if (item.value.isGranted) {
          return true;
        }
      }
    }
    return false;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants