I am sharing Pdf using whatsapp through my app But ItShowing Error (Sharing Failed {Please try again)

by Tarun Gandhi   Last Updated October 09, 2019 15:11 PM

package com.careerguide;

import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast;

public class ShareActivity extends AppCompatActivity {

private Context mContext;
private static final String AUTHORITY=
        "com.careerguide";

private static final Uri PROVIDER=
        Uri.parse("content://"+AUTHORITY);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_web_view);

    mContext = this;
    //shareAssetFile("sampletextfile.txt");
    // Setting Title

    String pdfsname = getIntent ( ).getStringExtra ( "filename" );
     shareAssetFile(pdfsname);
}
public void shareAssetFile(String pdfsname){
    Uri uriFile;
            .buildUpon()
            .appendPath(pdfsname)
            .build();
    String message = "Choose today Enjoy tomorrow - Make right career choices";
    Intent fileShareIntent = new Intent(Intent.ACTION_SEND);
    fileShareIntent.setType("*/*");
    fileShareIntent.putExtra(Intent.EXTRA_STREAM,uriFile);
    fileShareIntent.putExtra(Intent.EXTRA_TEXT, message);
    fileShareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    fileShareIntent.setPackage("com.whatsapp.w4b");
    try {
        startActivity(fileShareIntent);
    }
    catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(mContext,"Please Install Whatsapp", Toast.LENGTH_LONG).show();
    }
}

}



Related Questions


Updated September 28, 2017 06:11 AM

Updated January 30, 2017 14:04 PM

Updated April 11, 2016 08:04 AM

Updated March 02, 2016 06:04 AM

Updated August 20, 2016 08:04 AM