9

I have an application with share image on whatsapp in android. It was working till now.But now I get the following error

"The file format is not supported."

Nothing changed on code.

btnWhatsapp.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {   

        if (isAppInstalled("com.whatsapp"))   {
           // APP  INSTALLED
           Intent sendIntent = new Intent(Intent.ACTION_SEND);
           String sharetext ="Try my app";
           sendIntent.putExtra(Intent.EXTRA_TEXT,sharetext );
           Uri screenshotUri = Uri.parse("android.resource://"+getPackageName()+"/drawable/"+logofilename);
           sendIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
           sendIntent.setType("image/png");
           sendIntent.setPackage("com.whatsapp");
           v.getContext().startActivity(sendIntent);

        }else{
                        Toast.makeText(getApplicationContext(),R.string.nowhatsapp,Toast.LENGTH_SHORT).show();
                }                   
            }
       });
Molly
  • 1,887
  • 3
  • 17
  • 34
Stefan Ivalinov
  • 91
  • 1
  • 1
  • 2

5 Answers5

3

The file you are trying to share is in the package (your app) only your app can access the file. You need to share a public file

share.putExtra(Intent.EXTRA_STREAM,
        Uri.parse( Environment.getExternalStorageDirectory()+ File.separator+"temporary_file.jpg"));

like this other app can have access

Jason
  • 231
  • 3
  • 14
0

you need download image from url to sdcard and pick the path from sdcard to share to whatsapp

xuming liu
  • 11
  • 3
0

If anybody is facing this issue until now then I have figured it out somehow. Every directory containing the .nomedia file will not be available to share images/videos programmatically.

My application creates a directory in Android/media, I don't want to show all the clips in the gallery that's why I have created a .nomedia file programmatically but later I realised that if someone wants to share a video (on WhatsApp) using my application, the .nomedia file is not allowing my application to do so and eventually WhatsApp throws an error "The file format is not supported", it's happening on few devices. Delete this file and your app will be able to share videos. Although deleting this file is not recommended as it may flood the user's gallery with useless/duplicate clips and images but I couldn't find any other solution till now.

Adnan
  • 1,379
  • 2
  • 17
  • 24
-1
Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
whatsappIntent.setType("image/jpeg");
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

try {
    activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
mr.hir
  • 533
  • 1
  • 7
  • 19
-1

Check the permissions of your app, enable storage permissions in App permissions, it will solve your problem.