我的可绘制文件夹中有一些图像,还有这些图像的 int 数组。现在我正在尝试通过 gmail 发送带有我的可绘制文件夹中的附加图像的电子邮件,在 android 2.3 中一切正常,但在 android 4.0 中图像的扩展名丢失。我没有找到任何解决方案。下面是我使用的代码。
Uri imageuri = Uri.parse("android.resource://MyPackageName/" + SplashActivity.mBitmap_mixed_images[int_image_position]);
Intent intent = new Intent(Intent.ACTION_SEND);
if(imageuri != null){
intent.putExtra(Intent.EXTRA_STREAM, imageuri);
intent.putExtra(Intent.EXTRA_SUBJECT, "150+ Reasons to Quit Smoking");
//intent.putExtra(Intent.EXTRA_TEXT, "www.selftalk.info");
intent.setType("image/html");
}else{
intent.setType("plain/text");
}
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
intent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
startActivity(intent);
最佳答案
private FileOutputStream outStream;
private File file;
Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
file = new File(extStorageDirectory, "ic_launcher.PNG");
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
email = new Intent(Intent.ACTION_SEND);
email.setType("application/octet-stream");
email.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
email.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
email.putExtra(Intent.EXTRA_TEXT, "");
email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(email, "Choose an Email client :"));
关于android - 将可绘制文件夹中的图像附加到gmail中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18143199/