FaisalAhmed
FaisalAhmed

Reputation: 3651

I am trying to send a image to whatsapp but it Toast appears and says The file formate is not supported

I am trying to share image to whatsapp or other apps. Image is in drawable folder in android studio . But when i try to do so it Toasts that The file formate is not supported. Below is my code .Please Help thanks in advance

 public void share(View view)
{
    Uri uri=Uri.parse("android.resource://com.faisal.home.myapplication/drawable/"+R.drawable.tease);
    Intent intent,chooser;
    intent=new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_STREAM,uri);
    chooser=Intent.createChooser(intent,"share Image");
    if(intent.resolveActivity(getPackageManager())!=null)
    {
        startActivity(chooser);

    }
    else
    {

        Toast.makeText(this,"No app to share",Toast.LENGTH_LONG).show();
    }


}

Upvotes: 1

Views: 1232

Answers (1)

Amit Kukreja
Amit Kukreja

Reputation: 86

Try below mention code its working fine:

 try {
                    Uri imageUri = null;
                    try {
                        imageUri = Uri.parse(MediaStore.Images.Media.insertImage(Activity.getContentResolver(),
                                BitmapFactory.decodeResource(getResources(), R.drawable.yourimage), null, null));
                    } catch (NullPointerException e) {
                    }

                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("*/*");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, "your text");

                    shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri);

                    startActivity(shareIntent);
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(Activity, "no app fount", Toast.LENGTH_LONG).show();
                }

Upvotes: 5

Related Questions