我正在尝试启动Intent来发送电子邮件.所有这一切都有效,但当我尝试实际发送电子邮件时,会发生一些"奇怪"的事情.
这是代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/dcim/Camera/filename.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));
Run Code Online (Sandbox Code Playgroud)
因此,如果我使用Gmail菜单上下文启动它会显示附件,让我输入电子邮件的来源,并编辑正文和主题.没什么大不了.我点击发送,它发送.唯一的事情是附件不会被发送.
所以.我想,为什么不尝试使用电子邮件菜单上下文(对于我手机上的备份电子邮件帐户).它显示附件,但在身体或主体中根本没有文字.当我发送它时,附件发送正确.这会让我相信一些事情是错误的.我是否需要在Manifest发布中获得新的权限才能发送带附件的电子邮件?我究竟做错了什么?
我想pdf在gmail应用程序中附加一个文件.我已经读过这个和这个(应用的解决方案)我正在尝试;
public static void attachFile(Context ctx) {
String TAG = "Attach";
File documentsPath = new File(ctx.getFilesDir(), "documents");
Log.i(TAG,"documentsAbsolutePath Output");
Log.i(TAG, documentsPath.getAbsolutePath().toString());
File file = new File(documentsPath, "sample.pdf");
if ( file.exists() ) {
Toast.makeText(ctx, "Exits", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(ctx, "Not Exist", Toast.LENGTH_LONG).show();
}
Log.i(TAG,"file Output");
Log.i(TAG, file.toString());
Log.i(TAG, String.valueOf(file.length()));
Uri uri = FileProvider.getUriForFile(ctx, "com.example.fyp_awais.attachfiletest2.fileprovider", file);
Log.i(TAG,"URI Output");
Log.i(TAG,uri.toString());
Intent intent = ShareCompat.IntentBuilder.from((Activity) ctx)
.setType("application/pdf")
.setStream(uri)
.setChooserTitle("Choose bar")
.createChooserIntent()
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ctx.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
输出
documentsAbsolutePath Output
/data/data/com.example.fyp_awais.attachfiletest2/files/documents
file …Run Code Online (Sandbox Code Playgroud)