How can I attach an image file in email?

后端 未结 3 1253
独厮守ぢ
独厮守ぢ 2020-12-06 07:33

I want to attach an image with email, that image is stored in /data/data/mypacke/file.png. How can I attach that image file programmatically? What would sample

3条回答
  •  甜味超标
    2020-12-06 08:12

    Worth noting that if the file is located in internal storage and set to MODE_PRIVATE (which it should be) then you should set the file to be readable by other programs before launching the intent. Using the code from the answer,

    File F = new File("/path/to/your/file.png");
    F.setReadable(true, false);                     // This allows external program access
    Uri U = Uri.fromFile(F);
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("image/png");
    i.putExtra(Intent.EXTRA_STREAM, U);
    startActivity(Intent.createChooser(i,"Email:"));
    

提交回复
热议问题