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