1

I use the TelegramGallery library. I have some problems with ContentProvider. I created a lib for getting images from a gallery or something else. It works well and returns the path for the images list, but when I want to get URI for every image, the app throws

Caused by java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/0000-0000/TropicBeauty Austin/Screenshot_20170905-184459.jpg

The problem is with this piece of code:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ArrayList<String> fullMediaPath = new ArrayList<>();
    if(resultCode == android.app.Activity.RESULT_OK && requestCode == Const.OPEN_ATTACH_PHOTO_REQUEST_CODE){
        ArrayList<String> photos = (ArrayList<String>) data.getSerializableExtra(GalleryActivity.PHOTOS);
        fullMediaPath.addAll(photos);
        if(photos != null && photos.size()>0) {
            try {
                for (String photo : photos) {
                    File file = new File(photo);
                    Uri path = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file);
                    uriPhotos.add(path);
                }

This exception happens only on Samsung devices on Android 7.0 and I can't reproduce this crash. My provider_path.xml

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external_p"
        path="."/>
    <files-path
        name="files_p"
        path="." />
    <external-files-path
        name="ext_files"
        path="." />
    <cache-path
        name="cache_p"
        path="." />
    <external-cache-path
        name="external_cache_p"
        path="." />
</paths>

The code of set data in the intent

@Override
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions) {
    Intent intent = new Intent();
    intent.putExtra(PHOTOS, photos);
    setResult(Activity.RESULT_OK, intent);
}

Maybe I didn't write the correct path or name, but on any other devices, it works great. What is the problem with Samsung, I don't know. Maybe someone can help me?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Alex Khotiun
  • 431
  • 4
  • 16

0 Answers0