зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1450449 - Part 2: Use content:// URI for capturing images from FilePicker. r=jchen
Since it is only us and the camera app who have to deal with the content:// URI, it should be safe enough to use content:// URIs on all supported versions. MozReview-Commit-ID: JMIhBRlCiA4 --HG-- extra : rebase_source : 7a19ea138459f4a153a931db1500a0b2cb0649da
This commit is contained in:
Родитель
4a47c55e8f
Коммит
6020b72cc4
|
@ -179,7 +179,7 @@ public class FilePicker implements BundleEventListener {
|
|||
if (mimeType.equals("image/*") &&
|
||||
hasPermissionsForMimeType(mimeType, availPermissions)) {
|
||||
// We also add a capture intent
|
||||
Intent intent = IntentHelper.getImageCaptureIntent(
|
||||
Intent intent = IntentHelper.getImageCaptureIntent(context,
|
||||
new File(Environment.getExternalStorageDirectory(),
|
||||
fileHandler.generateImageName()));
|
||||
addActivities(intent, intents, baseIntents);
|
||||
|
@ -205,7 +205,7 @@ public class FilePicker implements BundleEventListener {
|
|||
addActivities(intent, intents, baseIntents);
|
||||
}
|
||||
if (hasPermissionsForMimeType("image/*", availPermissions)) {
|
||||
intent = IntentHelper.getImageCaptureIntent(
|
||||
intent = IntentHelper.getImageCaptureIntent(context,
|
||||
new File(Environment.getExternalStorageDirectory(),
|
||||
fileHandler.generateImageName()));
|
||||
addActivities(intent, intents, baseIntents);
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.mozilla.gecko.widget.ExternalIntentDuringPrivateBrowsingPromptFragmen
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
|
@ -24,6 +25,7 @@ import android.provider.Browser;
|
|||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
@ -243,10 +245,21 @@ public final class IntentHelper implements BundleEventListener {
|
|||
return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
||||
}
|
||||
|
||||
public static Intent getImageCaptureIntent(final File destinationFile) {
|
||||
public static Intent getImageCaptureIntent(final Context context, final File destinationFile) {
|
||||
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT,
|
||||
Uri.fromFile(destinationFile));
|
||||
Uri destination = FileProvider.getUriForFile(context,
|
||||
AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, destinationFile);
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT, destination);
|
||||
|
||||
if (AppConstants.Versions.preLollipop) {
|
||||
// As per https://github.com/commonsguy/cw-omnibus/blob/master/Camera/FileProvider/
|
||||
// app/src/main/java/com/commonsware/android/camcon/MainActivity.java - at least we
|
||||
// don't have to support anything below Jelly Bean.
|
||||
ClipData clip =
|
||||
ClipData.newUri(context.getContentResolver(), null, destination);
|
||||
intent.setClipData(clip);
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче