summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Miller <paulmiller@google.com>2015-10-28 13:26:18 -0700
committerPaul Miller <paulmiller@google.com>2015-10-28 20:48:01 +0000
commit0e4f86ba6d9b1a35c9b78a3bf2147208301280d3 (patch)
treefaff7bf5408d9e495ac9a6ee4c0266939480c6bc
parenteb41844b966152093b0077dc61dac010a11c1d08 (diff)
downloadHTMLViewer-0e4f86ba6d9b1a35c9b78a3bf2147208301280d3.tar.gz
Manual cherry-pick of "Update permission usage for M"
Manual cherry-pick of 72c99277ae6dd2a871a50189e1f45791108bb267 from internal/master to aosp/master BUG:24172966 Change-Id: I7c6d97555e72a8ae8297d64c747378c9ab09354e
-rw-r--r--AndroidManifest.xml3
-rw-r--r--src/com/android/htmlviewer/HTMLViewerActivity.java32
2 files changed, 34 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9a2ccd0..e97238b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -21,6 +21,9 @@
package="com.android.htmlviewer">
<original-package android:name="com.android.htmlviewer" />
+ <uses-sdk android:minSdkVersion="23"
+ android:targetSdkVersion="23" />
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:label="@string/app_label">
diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java
index adda32c..e31e4d4 100644
--- a/src/com/android/htmlviewer/HTMLViewerActivity.java
+++ b/src/com/android/htmlviewer/HTMLViewerActivity.java
@@ -20,6 +20,8 @@ import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.Manifest;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
@@ -47,6 +49,7 @@ public class HTMLViewerActivity extends Activity {
private WebView mWebView;
private View mLoading;
+ private Uri mOnPermissionDestination;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -79,7 +82,34 @@ public class HTMLViewerActivity extends Activity {
setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
}
- mWebView.loadUrl(String.valueOf(intent.getData()));
+ Uri destination = intent.getData();
+ if (destination != null) {
+ // Is this a local file?
+ if ("file".equals(destination.getScheme())) {
+ if (PackageManager.PERMISSION_DENIED ==
+ checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
+ // If we don't have local file permissions, save the destination so we can try
+ // again once they're granted.
+ mOnPermissionDestination = destination;
+ requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
+ }
+ }
+ mWebView.loadUrl(destination.toString());
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode,
+ String permissions[], int[] grantResults) {
+ // We only ever request 1 permission, so these arguments should always have the same form.
+ assert permissions.length == 1;
+ assert Manifest.permission.READ_EXTERNAL_STORAGE.equals(permissions[0]);
+ assert grantResults.length == 1;
+
+ if (PackageManager.PERMISSION_GRANTED == grantResults[0]) {
+ // Try again now that we have the permission.
+ mWebView.loadUrl(mOnPermissionDestination.toString());
+ }
}
@Override