I'm trying to send a text file using WhatsApp, the code seems to be correct, everything happens as expected, WhatsApp opens and I select a contact but when I click send, WhatsApp closes and doesn't send the file and doesn't show any error message, I hope someone can help me
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri u = Uri.parse("file:///storage/emulated/0/Android/data/com.mycompany.app/cache/test.txt");
startShare(this,u);
}
public void startShare(Context c, Uri u){
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("plain/*");
share.putExtra(Intent.EXTRA_STREAM, u);
share.putExtra(android.content.Intent.EXTRA_TEXT, "file description");
share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity)c).startActivity(Intent.createChooser(share,"share with"));
}