Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share image on whatsapp in Android "The file format is not supported." error

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();
                }                   
            }
       });
like image 710
Stefan Ivalinov Avatar asked Nov 19 '22 22:11

Stefan Ivalinov


1 Answers

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

like image 53
Jason Avatar answered Dec 18 '22 12:12

Jason