Unverified Commit b9d82d88 authored by singhalsara8's avatar singhalsara8 Committed by GitHub

Add permission for write external storage in sound recorder (#2021)

parent 13653adc
...@@ -18,6 +18,7 @@ import com.google.appinventor.components.common.ComponentCategory; ...@@ -18,6 +18,7 @@ import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants; import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion; import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.errors.PermissionException; import com.google.appinventor.components.runtime.errors.PermissionException;
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.FileUtil; import com.google.appinventor.components.runtime.util.FileUtil;
import android.Manifest; import android.Manifest;
...@@ -158,22 +159,18 @@ public final class SoundRecorder extends AndroidNonvisibleComponent ...@@ -158,22 +159,18 @@ public final class SoundRecorder extends AndroidNonvisibleComponent
*/ */
@SimpleFunction @SimpleFunction
public void Start() { public void Start() {
// Need to check if we have RECORD_AUDIO permission // Need to check if we have RECORD_AUDIO and WRITE_EXTERNAL permissions
if (!havePermission) { if (!havePermission) {
final SoundRecorder me = this; final SoundRecorder me = this;
form.runOnUiThread(new Runnable() { form.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
form.askPermission(Manifest.permission.RECORD_AUDIO, form.askPermission(new BulkPermissionRequest(me, "Start",
new PermissionResultHandler() { Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE) {
@Override @Override
public void HandlePermissionResponse(String permission, boolean granted) { public void onGranted() {
if (granted) {
me.havePermission = true; me.havePermission = true;
me.Start(); me.Start();
} else {
form.dispatchPermissionDeniedEvent(me, "Start", Manifest.permission.RECORD_AUDIO);
}
} }
}); });
} }
......
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