fix cannot delete media files in SnapdragonGallery
because of Android Q upgrade, Gallery need to grant
"Gallery" role to edit media files
Change-Id: I5f866d78ca23c8761acf2f9581897adf7fbe0d96
diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
index 824f6b9..7b3efb9 100755
--- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java
+++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
@@ -256,6 +256,7 @@
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
mGLRootView.lockRenderThread();
try {
getStateManager().notifyActivityResult(
diff --git a/src/com/android/gallery3d/app/AbstractPermissionActivity.java b/src/com/android/gallery3d/app/AbstractPermissionActivity.java
old mode 100644
new mode 100755
index f193e7f..8b32dbf
--- a/src/com/android/gallery3d/app/AbstractPermissionActivity.java
+++ b/src/com/android/gallery3d/app/AbstractPermissionActivity.java
@@ -30,10 +30,13 @@
import android.Manifest;
import android.app.Activity;
+import android.app.role.RoleManager;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
+import android.widget.Toast;
import java.util.ArrayList;
@@ -41,6 +44,7 @@
public static final int PERMISSION_REQUEST_STORAGE = 1;
private boolean permissionGranted = false;
+ private final int REQUEST_GALLERY_ROLE = 1001;
protected abstract void onGetPermissionsSuccess();
protected abstract void onGetPermissionsFailure();
@@ -49,6 +53,20 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestStoragePermission();
+ RoleManager roleManager = getSystemService(RoleManager.class);
+ if (!roleManager.isRoleHeld(RoleManager.ROLE_GALLERY)) {
+ startActivityForResult(roleManager.createRequestRoleIntent(RoleManager.ROLE_GALLERY),
+ REQUEST_GALLERY_ROLE);
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_GALLERY_ROLE && Activity.RESULT_CANCELED == resultCode) {
+ Toast.makeText(getApplicationContext(),
+ "Granting failed. SnapdragonGallery can't edit media files.",
+ Toast.LENGTH_SHORT).show();
+ }
}
private void requestStoragePermission() {