Unverified Commit 897d96d3 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey I. Schiller

Make Image.Picture ask for read permissions if needed

Change-Id: I98a2aa0ccb8b231634b4122044e7a82ee9e801bd
parent b730fa8d
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package com.google.appinventor.components.runtime; package com.google.appinventor.components.runtime;
import android.Manifest;
import com.google.appinventor.components.annotations.DesignerComponent; import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty; import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory; import com.google.appinventor.components.annotations.PropertyCategory;
...@@ -41,7 +42,8 @@ import java.io.IOException; ...@@ -41,7 +42,8 @@ import java.io.IOException;
"and other aspects of the Image's appearance, can be specified in the " + "and other aspects of the Image's appearance, can be specified in the " +
"Designer or in the Blocks Editor.") "Designer or in the Blocks Editor.")
@SimpleObject @SimpleObject
@UsesPermissions(permissionNames = "android.permission.INTERNET") @UsesPermissions(permissionNames = "android.permission.INTERNET," +
"android.permission.READ_EXTERNAL_STORAGE")
public final class Image extends AndroidViewComponent { public final class Image extends AndroidViewComponent {
private final ImageView view; private final ImageView view;
...@@ -101,7 +103,22 @@ public final class Image extends AndroidViewComponent { ...@@ -101,7 +103,22 @@ public final class Image extends AndroidViewComponent {
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET, @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET,
defaultValue = "") defaultValue = "")
@SimpleProperty @SimpleProperty
public void Picture(String path) { public void Picture(final String path) {
if (MediaUtil.isExternalFile(path) &&
container.$form().isDeniedPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
container.$form().askPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
new PermissionResultHandler() {
@Override
public void HandlePermissionResponse(String permission, boolean granted) {
if (granted) {
Picture(path);
} else {
container.$form().dispatchPermissionDeniedEvent(Image.this, "Picture", permission);
}
}
});
return;
}
picturePath = (path == null) ? "" : path; picturePath = (path == null) ? "" : path;
Drawable drawable; Drawable drawable;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment