Skip to content

Commit

Permalink
Use new storage permissions on Android >13
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasMizera committed Oct 5, 2023
1 parent 897285b commit 03d1d5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 13 additions & 1 deletion app/androidutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,19 @@ void AndroidUtils::quitApp()
bool AndroidUtils::requestStoragePermission()
{
#ifdef ANDROID
if ( !checkAndAcquirePermissions( "android.permission.READ_EXTERNAL_STORAGE" ) )
double buildVersion = QSysInfo::productVersion().toDouble();

//
// Android SDK 33 has a new set of permissions when reading external storage.
// See https://developer.android.com/reference/android/Manifest.permission#READ_EXTERNAL_STORAGE
//
QString storagePermissionType = QStringLiteral( "android.permission.READ_MEDIA_IMAGES" );
if ( buildVersion < ANDROID_VERSION_13 )
{
storagePermissionType = QStringLiteral( "android.permission.READ_EXTERNAL_STORAGE" );
}

if ( !checkAndAcquirePermissions( storagePermissionType ) )
{
auto activity = QJniObject( QNativeInterface::QAndroidApplication::context() );
jboolean res = activity.callMethod<jboolean>( "shouldShowRequestPermissionRationale", "(Ljava/lang/String;)Z", QJniObject::fromString( "android.permission.WRITE_EXTERNAL_STORAGE" ).object() );
Expand Down
2 changes: 2 additions & 0 deletions app/androidutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class AndroidUtils: public QObject
const static int INSTALL_QR_SCANNER_CODE = 104;
const static int QR_SCAN_CODE = 105;

const static int ANDROID_VERSION_13 = 13;

void handleActivityResult( int receiverRequestCode, int resultCode, const QJniObject &data ) override;
#endif

Expand Down
9 changes: 4 additions & 5 deletions cmake_templates/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
android:versionCode="@INPUT_VERSION_CODE@"
android:versionName="@INPUT_VERSION@">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <!-- Need due to a legacy storage migration -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/> <!-- Read images from gallery, Android <=12 -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/> <!-- Read images from gallery, Android 13+ -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> <!-- BT permission up to SDK 30-->
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /> <!-- BT permission up to SDK 30-->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"/> <!-- Reading compass while taking a picture -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
Expand All @@ -31,13 +32,11 @@
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<!-- "preserveLegacyExternalStorage" is needed to support legacy storage migration -->
<!-- "allowBackup" is suspicious, see https://developer.android.com/guide/topics/manifest/application-element#allowbackup -->
<application
android:name="org.qtproject.qt.android.bindings.QtApplication"
android:hardwareAccelerated="true"
android:label="Mergin Maps"
android:preserveLegacyExternalStorage="true"
android:allowNativeHeapPointerTagging="false"
android:allowBackup="true"
android:fullBackupOnly="false"
Expand Down

1 comment on commit 03d1d5b

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.10.463511 just submitted!

Please sign in to comment.