summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Miller <paulmiller@google.com>2015-11-11 00:45:00 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-11-11 00:45:00 +0000
commit1c4d66139d8e917e58ebe2ddc27d7db03934e518 (patch)
tree043a2a171d3f97aff4e30ed44f691c4496a3c41f
parent7a9a3ba729826e655ea0d2bad7c8151e7267542d (diff)
parent5af4cf9e89c488c92dab9f8bafe81b85ce237c4a (diff)
downloadandroid_packages_apps_HTMLViewer-1c4d66139d8e917e58ebe2ddc27d7db03934e518.tar.gz
android_packages_apps_HTMLViewer-1c4d66139d8e917e58ebe2ddc27d7db03934e518.tar.bz2
android_packages_apps_HTMLViewer-1c4d66139d8e917e58ebe2ddc27d7db03934e518.zip
Merge "Reload data after the permission is granted" am: 935203f1c6 am: d9e7e17b3a
am: 5af4cf9e89 * commit '5af4cf9e89c488c92dab9f8bafe81b85ce237c4a': Reload data after the permission is granted
-rw-r--r--res/values/strings.xml1
-rw-r--r--src/com/android/htmlviewer/HTMLViewerActivity.java38
2 files changed, 24 insertions, 15 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5f3a124..28b5a6f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -18,5 +18,6 @@
<!-- Title of the HTML Viewer activity. -->
<string name="app_label">HTML Viewer</string>
<string name="cannot_open_link">No application can open this link.</string>
+ <string name="turn_on_storage_permission">Please turn on Storage permission in app permissions.</string>
</resources>
diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java
index e31e4d4..aca339f 100644
--- a/src/com/android/htmlviewer/HTMLViewerActivity.java
+++ b/src/com/android/htmlviewer/HTMLViewerActivity.java
@@ -49,7 +49,7 @@ public class HTMLViewerActivity extends Activity {
private WebView mWebView;
private View mLoading;
- private Uri mOnPermissionDestination;
+ private Intent mIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -77,24 +77,28 @@ public class HTMLViewerActivity extends Activity {
s.setJavaScriptEnabled(false);
s.setDefaultTextEncodingName("utf-8");
- final Intent intent = getIntent();
- if (intent.hasExtra(Intent.EXTRA_TITLE)) {
- setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
+ mIntent = getIntent();
+ requestPermissionAndLoad();
+ }
+
+ private void loadUrl() {
+ if (mIntent.hasExtra(Intent.EXTRA_TITLE)) {
+ setTitle(mIntent.getStringExtra(Intent.EXTRA_TITLE));
}
+ mWebView.loadUrl(String.valueOf(mIntent.getData()));
+ }
- Uri destination = intent.getData();
+ private void requestPermissionAndLoad() {
+ Uri destination = mIntent.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);
- }
+ if ("file".equals(destination.getScheme())
+ && PackageManager.PERMISSION_DENIED ==
+ checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
+ requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
+ } else {
+ loadUrl();
}
- mWebView.loadUrl(destination.toString());
}
}
@@ -108,7 +112,11 @@ public class HTMLViewerActivity extends Activity {
if (PackageManager.PERMISSION_GRANTED == grantResults[0]) {
// Try again now that we have the permission.
- mWebView.loadUrl(mOnPermissionDestination.toString());
+ loadUrl();
+ } else {
+ Toast.makeText(HTMLViewerActivity.this,
+ R.string.turn_on_storage_permission, Toast.LENGTH_SHORT).show();
+ finish();
}
}