Skip to content

Commit

Permalink
request media_location
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Dec 27, 2024
1 parent 0b11747 commit 42e0bfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
android:maxSdkVersion="25" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<!--
Apps that target Android 9 (API level 28) or higher and use foreground services
must request the FOREGROUND_SERVICE permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;

import javax.inject.Inject;

Expand Down Expand Up @@ -491,6 +490,9 @@ public void registerFabListener() {
// is not available in FolderPickerActivity
viewThemeUtils.material.themeFAB(mFabMain);
mFabMain.setOnClickListener(v -> {
PermissionUtil.requestMediaLocationPermission(activity);


final OCFileListBottomSheetDialog dialog =
new OCFileListBottomSheetDialog(activity,
this,
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/PermissionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object PermissionUtil {
const val PERMISSIONS_READ_CALENDAR_AUTOMATIC = 6
const val PERMISSIONS_WRITE_CALENDAR = 7
const val PERMISSIONS_POST_NOTIFICATIONS = 8
const val PERMISSIONS_MEDIA_LOCATION = 9

const val REQUEST_CODE_MANAGE_ALL_FILES = 19203

Expand Down Expand Up @@ -302,4 +303,23 @@ object PermissionUtil {
}
}
}

/**
* Request media location permission. Required on API level >= 34.
* Does not have any effect on API level < 34.
*
* @param activity target activity
*/
@JvmStatic
fun requestMediaLocationPermission(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (!checkSelfPermission(activity, Manifest.permission.ACCESS_MEDIA_LOCATION)) {
ActivityCompat.requestPermissions(
activity,
arrayOf(Manifest.permission.ACCESS_MEDIA_LOCATION),
PERMISSIONS_POST_NOTIFICATIONS
)
}
}
}
}

0 comments on commit 42e0bfd

Please sign in to comment.