>From 9cd1ed5b539a2a14a13e19312c669afa2ace73d8 Mon Sep 17 00:00:00 2001
From: Ruben Roy <rubenroy2005(a)gmail.com>
Date: Sat, 22 Nov 2014 01:40:22 +0530
Subject: [PATCH] Use storage access framework to select image on kitkat
---
.../org/fedorahosted/freeotp/add/AddActivity.java | 18 ++++++++++++++--
.../fedorahosted/freeotp/edit/EditActivity.java | 24 ++++++++++++++++++----
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/app/src/main/java/org/fedorahosted/freeotp/add/AddActivity.java
b/app/src/main/java/org/fedorahosted/freeotp/add/AddActivity.java
index 6c6d3dd..9cebba7 100644
--- a/app/src/main/java/org/fedorahosted/freeotp/add/AddActivity.java
+++ b/app/src/main/java/org/fedorahosted/freeotp/add/AddActivity.java
@@ -30,6 +30,7 @@ import org.fedorahosted.freeotp.TokenPersistence;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.text.TextWatcher;
import android.view.View;
@@ -92,8 +93,17 @@ public class AddActivity extends Activity
implements View.OnClickListener, Compo
public void onClick(View view) {
switch (view.getId()) {
case R.id.image:
- startActivityForResult(new Intent(Intent.ACTION_PICK,
-
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 0);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType("image/*");
+ startActivityForResult(intent,0);
+
+ }
+ else {
+ startActivityForResult(new Intent(Intent.ACTION_PICK,
+
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 0);
+ }
break;
case R.id.cancel:
@@ -148,6 +158,10 @@ public class AddActivity extends Activity
implements View.OnClickListener, Compo
if (resultCode == RESULT_OK) {
mImageURL = data.getData();
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ final int takeFlags = data.getFlags() &
Intent.FLAG_GRANT_READ_URI_PERMISSION;
+
getContentResolver().takePersistableUriPermission(mImageURL,
takeFlags);
+ }
Picasso.with(this)
.load(mImageURL)
.placeholder(R.drawable.logo)
diff --git a/app/src/main/java/org/fedorahosted/freeotp/edit/EditActivity.java
b/app/src/main/java/org/fedorahosted/freeotp/edit/EditActivity.java
index 575d1ad..a9550ff 100644
--- a/app/src/main/java/org/fedorahosted/freeotp/edit/EditActivity.java
+++ b/app/src/main/java/org/fedorahosted/freeotp/edit/EditActivity.java
@@ -26,6 +26,7 @@ import org.fedorahosted.freeotp.TokenPersistence;
import android.content.Intent;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@@ -112,8 +113,14 @@ public class EditActivity extends BaseActivity
implements TextWatcher, View.OnCl
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == RESULT_OK)
- showImage(data.getData());
+ if (resultCode == RESULT_OK) {
+ Uri uri = data.getData();
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ final int takeFlags = data.getFlags() &
Intent.FLAG_GRANT_READ_URI_PERMISSION;
+
getContentResolver().takePersistableUriPermission(uri, takeFlags);
+ }
+ showImage(uri);
+ }
}
@Override
@@ -138,8 +145,17 @@ public class EditActivity extends BaseActivity
implements TextWatcher, View.OnCl
public void onClick(View v) {
switch (v.getId()) {
case R.id.image:
- startActivityForResult(new Intent(Intent.ACTION_PICK,
-
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 0);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType("image/*");
+ startActivityForResult(intent,0);
+
+ }
+ else {
+ startActivityForResult(new Intent(Intent.ACTION_PICK,
+
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 0);
+ }
break;
case R.id.restore:
--
1.9.3