gpt4 book ai didi

Android:在 htc Hero 上选择 Gmail 应用程序时,带有 EXTRA_STREAM 的 Intent.ACTION_SEND 不会附加任何图像

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:39 26 4
gpt4 key购买 nike

在带有默认邮件应用程序的模拟器上一切正常。但是当我收到一封我的英雄使用 Gmail 应用程序发送的邮件时,我没有附件。 hero 上的默认邮件应用程序运行良好。

如何使此代码与 Hero 上的 Gmail 应用程序一起使用?
你可以看到下面的代码。

    private void startSendIntent() {
Bitmap bitmap = Bitmap.createBitmap(editableImageView.getWidth(), editableImageView.getHeight(), Bitmap.Config.RGB_565);
editableImageView.draw(new Canvas(bitmap));
File png = getFileStreamPath(getString(R.string.file_name));
FileOutputStream out = null;
try {
out = openFileOutput(getString(R.string.file_name), MODE_WORLD_READABLE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) out.close();
}
catch (IOException ignore) {}
}
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(png));
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_intent_name)));
}

在日志中我看到以下内容:

02-05 17:03:37.526: DEBUG/Gmail(11511): URI FOUND:file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg
02-05 17:03:37.535: DEBUG/Gmail(11511): ComposeActivity added to message:0 attachment:|IMAG0001.jpg|image/jpeg|0|image/jpeg|LOCAL_FILE|file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg size:0
02-05 17:03:37.585: INFO/Gmail(11511): >>>>> Attachment uri: file:///sdcard/DCIM/100MEDIA/IMAG0001.jpg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>> type: image/jpeg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>> name: IMAG0001.jpg
02-05 17:03:37.585: INFO/Gmail(11511): >>>>> size: 0

谢谢你的回答。

最佳答案

对我来说,问题是通过以下代码行解决的:

Bitmap screenshot = Bitmap.createBitmap(_rootView.getWidth(), _rootView.getHeight(), Bitmap.Config.RGB_565);
_rootView.draw(new Canvas(screenshot));

String path = Images.Media.insertImage(getContentResolver(), screenshot, "title", null);
Uri screenshotUri = Uri.parse(path);

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");

startActivity(Intent.createChooser(emailIntent, "Send email using"));

关键是我将屏幕截图保存到媒体库,然后它可以从那里成功发送文件。

关于Android:在 htc Hero 上选择 Gmail 应用程序时,带有 EXTRA_STREAM 的 Intent.ACTION_SEND 不会附加任何图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2206397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com