3

My code is working fine without image to send but when I am send data with image it shows error. If you are giving me some url there answer has been posted before so make sure that answer is correct because I tried lots of answer on stackoverflow.

Here is my code.

    Uri contentUri = Uri.parse("android.resource://" + BuildConfig.APPLICATION_ID + "/drawable/" + "ic_launcher");

            if (contentUri != null) {
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
//                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
                shareIntent.setType("text/plain");
                shareIntent.setType("image/*");
                shareIntent.putExtra(Intent.EXTRA_TEXT, "MY messgae");
                shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
                try {
                    startActivity(Intent.createChooser(shareIntent, "Share via"));
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(getContext(), "No App Available", Toast.LENGTH_SHORT).show();
                }
            }

It showing error that is sendind data failed try again later I am unable to getting my error.

BlackBlind
  • 772
  • 9
  • 26
  • `android.resource` reside inside the APK its not available to read/write .. You need to provide a path of Intenal/External storage which is available to Read . In a nut Shell you need to save this image first on Storage and then use this url to share . – ADM May 10 '19 at 10:11
  • 2
    Possible duplicate of [Sharing a png image in drawable folder](https://stackoverflow.com/questions/18502598/sharing-a-png-image-in-drawable-folder) – ADM May 10 '19 at 10:12

0 Answers0