Is there a way to get around size limit for “Uploa

2019-09-21 00:41发布

问题:

I'm using this code to share a collection of images:

final ArrayList<Uri> imageUris = new ArrayList<>();
for (final ImageBean selectedImage : ImageBean.getSelectedImageBeans(imagesBeans)) {
    final File imageFile = new File(selectedImage.getPathToImage().getPath());
    final Uri contentProviderUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", imageFile);
    imageUris.add(contentProviderUri);
}
final Intent shareIntent = new Intent();
shareIntent.setType("image/*");
if (imageUris.size() == 1) {
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUris.get(0));
} else {
    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
}
context.startActivity(Intent.createChooser(shareIntent, context.getResources().getText(R.string.share_images_intent)));

I'm mainly interested in uploading to Google Photos. This works great for an image of 600KB, but fails for a 5 MB image (24MP from my camera). So apparently there's a size limit, but as the error happens in the Google Photos activity, I'm unable to debug it (or I don't know Android Studio well enough on how to do that).

Is there a way I can change my Intent so I can upload multiple 24MP images, or is the size limit a given and I need to work around it (eg. by implementing the Google Photos API)?

回答1:

It turns out that Google Photos doesn't play well with the FileProvider. The upload works when using the public content URI, to be found using something like

int mediaId = cursor.getInt(getColumnIndexForMediaID());
Uri publicUri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(mediaId));

Now I'm back at Can't edit image in Google Photos after "Upload to Photos" activity