BearND has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247770
Change subject: 6.0 runtime permission for save image from gallery
......................................................................
6.0 runtime permission for save image from gallery
Added runtime permission checks for write external storage in gallery.
Note this patch does not address the share a fact functionality since
it doesn't currently work, see T116120.
The runtime check are used once target SDK level is set to 23.
I'll let a later patch change this value, once we're done with all the
permission checks and the backup check.
Bug: T113750
Change-Id: I356a736a0d84c99e05e0a6ae1784f99c1c59779e
---
M app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
3 files changed, 48 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/70/247770/1
diff --git
a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
index 99cfc95..3373e33 100644
--- a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
+++ b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
@@ -7,6 +7,8 @@
import org.wikipedia.util.FeedbackUtil;
import org.wikipedia.util.ShareUtils;
+import android.Manifest;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
@@ -14,7 +16,9 @@
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
+import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@@ -38,6 +42,7 @@
public static final String ARG_PAGETITLE = "pageTitle";
public static final String ARG_MEDIATITLE = "imageTitle";
public static final String ARG_MIMETYPE = "mimeType";
+ private static final int WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST = 44;
private WikipediaApp app;
private GalleryActivity parentActivity;
@@ -169,7 +174,7 @@
}
return true;
case R.id.menu_gallery_save:
- saveImageToMediaStore();
+ checkPermissionsToSaveImage();
return true;
case R.id.menu_gallery_share:
shareImage();
@@ -420,6 +425,45 @@
}
/**
+ * Checks runtime permissions first. If allowed it then proceeds with
saving the image
+ * to the MediaStore.
+ */
+ private void checkPermissionsToSaveImage() {
+ if (ContextCompat.checkSelfPermission(getActivity(),
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
+
requestWriteStorageRuntimePermissions(WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST);
+ } else {
+ saveImageToMediaStore();
+ }
+ }
+
+ private void requestWriteStorageRuntimePermissions(int requestCode) {
+ requestPermissions(new
String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
+ // once permission is granted/denied it will continue with
onRequestPermissionsResult
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode,
+ @NonNull String permissions[],
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST: {
+ // If request is cancelled, the result arrays are empty.
+ if (grantResults.length > 0
+ && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
+ saveImageToMediaStore();
+ } else {
+ // denied. boo!
+ Log.e(TAG, "Write permission was denied by user");
+ FeedbackUtil.showMessage(getActivity(),
+
R.string.gallery_save_image_write_permission_rationale);
+ }
+ break;
+ }
+ }
+ }
+
+ /**
* Save the current image to the MediaStore of the local device ("Photos"
/ "Gallery" / etc).
*/
private void saveImageToMediaStore() {
diff --git a/app/src/main/res/values-qq/strings.xml
b/app/src/main/res/values-qq/strings.xml
index 2179011..f01041e 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -331,6 +331,7 @@
<string name="gallery_image_saved_notification_title">Message shown when an
image is saved to the device.</string>
<string name="gallery_image_saved_notification_text">Message inviting the
user to touch the notification to view the saved image.</string>
<string name="gallery_error_video_failed">Error message displayed when a
video fails to be played on the device.</string>
+ <string name="gallery_save_image_write_permission_rationale">Message shown
to explain that an extra write permission is needed to save an image.</string>
<string name="err_cannot_save_file">Error message when we detect that a file
cannot be written to storage.</string>
<string name="snippet_share_intro">Intro text included as part of the shared
text snippet, aka Tweet-a-fact. Please do not translate the \"@Wikipedia\" in
the message and preserve the spaces around it, as it refers specifically to
Wikipedia\'s Twitter account. This message has two parameters. Please keep the
parameters exactly as in the original English message.
* %1$s is the title of the page the text snippet is from.
diff --git a/app/src/main/res/values/strings.xml
b/app/src/main/res/values/strings.xml
index 07b9652..6f4b5ca 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -262,6 +262,7 @@
<string name="gallery_image_saved_notification_title">Image saved.</string>
<string name="gallery_image_saved_notification_text">Touch to
view.</string>
<string name="gallery_error_video_failed">Could not play the
video.</string>
+ <string name="gallery_save_image_write_permission_rationale">To be able to
save the image write access to photos, media, and files on your device are
required.</string>
<string name="err_cannot_save_file">Cannot save file</string>
<string name="snippet_share_intro">\"%1$s\" on @Wikipedia: %2$s</string>
<string name="expand_refs">Tap to expand</string>
@@ -300,4 +301,5 @@
<string name="crash_report_relaunch">Start over</string>
<string name="crash_report_quit">Quit</string>
<!-- /Crash reporter -->
+
</resources>
--
To view, visit https://gerrit.wikimedia.org/r/247770
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I356a736a0d84c99e05e0a6ae1784f99c1c59779e
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits