RE: Setting permissions in Extension Manifest File?

Hi Anke

I have an extension that currently declares permissions like this in the manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Has apparently been working OK for users.

With the arrival of the new media permissions do I change to this to achieve the same result ?

<uses-permission android:maxSdkVersion="32" android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="34" android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:maxSdkVersion="34" android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:maxSdkVersion="34" android:name="android.permission.READ_MEDIA_VIDEO"/>

Thanks

Tim

Basically it doesn't matter whether "maxSdkVersion" is defined, because the respective permissions are not available above this maxSdkVersion anyway. In other words, if for example WRITE permission is requested on Android 11+, you will receive an error message. The same applies to READ on Android 13+. In this respect it would simply declare like this (following the AI2 approach, although with WRITE, as I said, the maxSdk cannot also be omitted):

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>

Incidentally, it can hardly be assumed that the READ_MEDIA_... permissions will no longer be available from Android 15. In this respect, android:maxSdkVersion="34" wouldn't make any sense anyway.

OK, thanks, will try it out.

Hmmm

Intellij tells me that the attribute: android:maxSdkVersion is not allowed here (manifest.xml file)

I use Visual Studio Code to edit my extensions, and the error is not reported. Managed to compile a Rush extension with these permissions successfully, and the permissions are reflected in the app manifest.

Extension manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.simpletest">
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
  <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
  <application>
  </application>
</manifest>

App manifest: (decompiled with APK Editor Studio)

<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="33" android:compileSdkVersionCodename="13" package="appinventor.ai_EMAILREMOVED.Hello" platformBuildVersionCode="33" platformBuildVersionName="13">
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application android:debuggable="false" android:icon="@mipmap/ic_launcher" android:label="Hello" android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication" android:networkSecurityConfig="@xml/network_security_config" android:preserveLegacyExternalStorage="true" android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
        <uses-library android:name="org.apache.http.legacy" android:required="false"/>
        <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize" android:exported="true" android:name=".Screen1" android:screenOrientation="unspecified" android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <provider android:authorities="appinventor.ai_EMAILREMOVED.Hello.provider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
        </provider>
    </application>
</manifest>

Hmmm, extension builds OK with the maxSdkVersion in place. Will test it.

I see you have your permissions inside <application>...</application> which intelliJ does not like either!

1 Like

I apologize. You are correct, the permissions are supposed to be placed outside of the application tag, but Rush seems to build fine anyway. Will edit my post.

1 Like

Btw, if DefaultFileScope is set to Legacy the APK's Manifest does not declare

<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

but

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

So like I said, it doesn't matter if you set android:maxSdkVersion.

2 Likes

I have gone with this for now in the manifest of the extension:

  <uses-permission android:name="android.permission.INTERNET" />
  <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_MEDIA_AUDIO" />
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
  <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

will have to see what issues may arise in the wild....

Thanks to Anke and Gordon for help and advice

I think there won't be any problems with declaring permissions this way.
However, problems will most likely arise with (correctly) requesting permissions (at the respective API levels).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.