Bug 1410975 - Support recording audio via supported app from the file picker. r?nechen
Unlike capturing images/videos, the Android permission for recording audio is apparently only required if we want to record the audio ourselves, but not if we're merely calling out to some other app via MediaStore.Audio.Media.RECORD_SOUND_ACTION. Therefore we can drop that permission request for now.
MozReview-Commit-ID: 35vtm8Y78hh
--- a/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
@@ -108,23 +108,23 @@ public class FilePicker implements Bundl
}, tabId);
}
});
}
}
private static String[] getPermissionsForMimeType(final String mimeType) {
if (mimeType.startsWith("audio/")) {
- return new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE };
+ return new String[] { Manifest.permission.READ_EXTERNAL_STORAGE };
} else if (mimeType.startsWith("image/")) {
return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
} else if (mimeType.startsWith("video/")) {
return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
}
- return new String[] { Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE };
+ return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
}
private static boolean hasPermissionsForMimeType(final String mimeType, final String[] availPermissions) {
return Arrays.asList(availPermissions)
.containsAll(Arrays.asList(getPermissionsForMimeType(mimeType)));
}
private void addActivities(Intent intent, HashMap<String, Intent> intents, HashMap<String, Intent> filters) {
@@ -155,19 +155,25 @@ public class FilePicker implements Bundl
Intent baseIntent;
// A HashMap of Activities the base intent will show in the chooser. This is used
// to filter activities from other intents so that we don't show duplicates.
HashMap<String, Intent> baseIntents = new HashMap<String, Intent>();
// A list of other activities to show in the picker (and the intents to launch them).
HashMap<String, Intent> intents = new HashMap<String, Intent> ();
if (mimeType.startsWith("audio/")) {
- // For audio the only intent is the mimetype
baseIntent = getIntent(mimeType);
addActivities(baseIntent, baseIntents, null);
+
+ if (mimeType.equals("audio/*") &&
+ hasPermissionsForMimeType(mimeType, availPermissions)) {
+ // We also add a capture intent
+ Intent intent = IntentHelper.getAudioCaptureIntent();
+ addActivities(intent, intents, baseIntents);
+ }
} else if (mimeType.startsWith("image/")) {
baseIntent = getIntent(mimeType);
addActivities(baseIntent, baseIntents, null);
if (mimeType.equals("image/*") &&
hasPermissionsForMimeType(mimeType, availPermissions)) {
// We also add a capture intent
Intent intent = IntentHelper.getImageCaptureIntent(
@@ -185,16 +191,20 @@ public class FilePicker implements Bundl
Intent intent = IntentHelper.getVideoCaptureIntent();
addActivities(intent, intents, baseIntents);
}
} else {
baseIntent = getIntent("*/*");
addActivities(baseIntent, baseIntents, null);
Intent intent;
+ if (hasPermissionsForMimeType("audio/*", availPermissions)) {
+ intent = IntentHelper.getAudioCaptureIntent();
+ addActivities(intent, intents, baseIntents);
+ }
if (hasPermissionsForMimeType("image/*", availPermissions)) {
intent = IntentHelper.getImageCaptureIntent(
new File(Environment.getExternalStorageDirectory(),
fileHandler.generateImageName()));
addActivities(intent, intents, baseIntents);
}
if (hasPermissionsForMimeType("video/*", availPermissions)) {
intent = IntentHelper.getVideoCaptureIntent();
--- a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
@@ -234,16 +234,20 @@ public final class IntentHelper implemen
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(BrowserContract.SKIP_TAB_QUEUE_FLAG, true);
intent.putExtra(INTENT_EXTRA_TAB_ID, tab.getId());
intent.putExtra(INTENT_EXTRA_SESSION_UUID, GeckoApplication.getSessionUUID());
return intent;
}
+ public static Intent getAudioCaptureIntent() {
+ return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
+ }
+
public static Intent getImageCaptureIntent(final File destinationFile) {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(destinationFile));
return intent;
}
public static Intent getVideoCaptureIntent() {