最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - share text file with WhatsApp - Stack Overflow

programmeradmin9浏览0评论

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"));
    
}
发布评论

评论列表(0)

  1. 暂无评论