我正在开发一个应用程序,我正在使用EditText字段( textArea.setDrawingCacheEnabled(true); textArea.buildDrawingCache(true); )生成图像并将其保存在SD卡上。同时我希望使用ACTION_SEND意图在其他应用之间共享该图像。这里我面临的问题是我能够从EditText生成图像但是相同的图像没有附加到意图(在这个例子中共享意图),请告诉我我在哪里我错了..
提前致谢..
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File picDir = new File(Environment.getExternalStorageDirectory()
+ "/myPic");
if (!picDir.exists()) {
picDir.mkdir();
}
textArea.setDrawingCacheEnabled(true);
textArea.buildDrawingCache(true);
Bitmap bitmap = textArea.getDrawingCache();
Date date = new Date();
String fileName = "img" + date.getTime() + ".png";
File picFile = new File(picDir + "/" + fileName);
try {
picFile.createNewFile();
FileOutputStream picOut = new FileOutputStream(picFile);
boolean saved = bitmap.compress(CompressFormat.PNG, 100,
picOut);
if (saved) {
Toast.makeText(
getApplicationContext(),
"Image saved to your device Pictures "
+ "directory!", Toast.LENGTH_SHORT).show();
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory() +"/" +picFile));
startActivity(Intent.createChooser(share, "Send picture using:"));
} else {
//Error
}
picOut.close();
} catch (Exception e) {
e.printStackTrace();
}
textArea.destroyDrawingCache();
} else {
//Error
}
答案 0 :(得分:1)
以下是我用于将文件附加到电子邮件的内容:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.lorem));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.lorem));
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.send_mail)));
这应该适合你。