Commit 2d5a7d52 authored by Evan W. Patton's avatar Evan W. Patton Committed by Susan Rati Lane

Make Camera ask permission to write to external storage (#1906)

Change-Id: I44b3780a0475b66555b84a0e3ed94de2196fdb6e
parent caa489f3
...@@ -15,6 +15,7 @@ import com.google.appinventor.components.annotations.SimpleProperty; ...@@ -15,6 +15,7 @@ import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions; import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory; import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.YaVersion; import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.util.BulkPermissionRequest;
import com.google.appinventor.components.runtime.util.ErrorMessages; import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil; import com.google.appinventor.components.runtime.util.NougatUtil;
...@@ -114,35 +115,24 @@ public class Camera extends AndroidNonvisibleComponent ...@@ -114,35 +115,24 @@ public class Camera extends AndroidNonvisibleComponent
*/ */
@SimpleFunction @SimpleFunction
public void TakePicture() { public void TakePicture() {
Date date = new Date();
String state = Environment.getExternalStorageState();
if (!havePermission) { if (!havePermission) {
final Camera me = this; final Camera me = this;
form.runOnUiThread(new Runnable() { form.askPermission(new BulkPermissionRequest(this, "TakePicture",
@Override Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE) {
public void run() {
form.askPermission(Manifest.permission.CAMERA,
new PermissionResultHandler() {
@Override @Override
public void HandlePermissionResponse(String permission, boolean granted) { public void onGranted() {
if (granted) {
me.havePermission = true; me.havePermission = true;
me.TakePicture(); me.TakePicture();
} else {
form.dispatchPermissionDeniedEvent(me, "TakePicture",
Manifest.permission.CAMERA);
}
}
});
} }
}); });
return; return;
} }
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) { if (Environment.MEDIA_MOUNTED.equals(state)) {
Log.i("CameraComponent", "External storage is available and writable"); Log.i("CameraComponent", "External storage is available and writable");
imageFile = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), imageFile = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"/Pictures/app_inventor_" + date.getTime() "/Pictures/app_inventor_" + new Date().getTime()
+ ".jpg")); + ".jpg"));
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
......
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