1

I am working on Wallpaper app, in which user can set wallpaper and share that wallpaper also via bluetooth, and other apps also. I have used following to identify user selected wallpaper.

ImageView imagePreview = (ImageView) findViewById(R.id.iv_preview);
imagePreview.setTag("a1");

And used getTag() in my another function to use that selected wallpaper.

To share the user selected image i have used following code

String mDrawableName = (String) imagePreview.getTag();
Uri imageUri = Uri.parse("android.resource://com.mypackage.wallpaperapp/drawable/"+mDrawableName);
Log.d("here i got", imageUri.toString()); // here i got  android.resource://com.mypackage.wallpaperapp/drawable/a3
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share From"));

But i am getting the the error in device that " file unknown file cannot send", Where am i wrong here?

I found in some stuff that i have to firstly save my image resource into storage and after that i can send my image. But i dont know how can i save my image resource file into storage and send it to via different apps.

Please Help.

1 Answers1

0

Maybe this answer can help you:

https://stackoverflow.com/a/19618432/3743093

In short: you can't pass an URI created with

Uri uri = Uri.parse(String);

to shareIntent, beacuse it lacks info like TITLE and MIME_TYPE. That's because file type is unknown (missing) and throws this error.

ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Uri.parse(filename),
        values);

Hope this helps.

Community
  • 1
  • 1
Rudy
  • 181
  • 2
  • 10