我想使用android隐含意图发送图像。所以我的代码是
Uri imageUri = Uri.parse("android.resource://com.example.intenttest/drawble/"+R.drawable.che3);
intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Image Sending");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "I AM ATTACHED THIS IMAGE");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
chooser = Intent.createChooser(intent, "Send Image");
startActivity(chooser);
图片的名称是che3.gif,它位于drawable文件夹中。我尝试使用png格式,我也阅读了stackoverflow questions this 和this我跟着第一个但没有用。但是它给出了无法确定mime类型的错误。下面是log cat
I/ActivityManager( 287): START u0 {act=android.intent.action.SEND typ=image/png flg=0x3000001 cmp=com.android.email/.activity.MessageCompose (has clip) (has extras)} from pid 2180
E/Email ( 749): Unable to determine MIME type for uri=android.resource://com.example.intenttest/drawble/2130837504
E/Email ( 749): java.lang.Error
E/Email ( 749): at com.android.emailcommon.utility.AttachmentUtilities.inferMimeTypeForUri(AttachmentUtilities.java:251)
E/Email ( 749): at com.android.email.activity.MessageCompose.loadAttachmentInfo(MessageCompose.java:1607)
E/Email ( 749): at com.android.email.activity.MessageCompose.addAttachmentFromSendIntent(MessageCompose.java:1674)
E/Email ( 749): at com.android.email.activity.MessageCompose.initFromIntent(MessageCompose.java:2028)
任何人都可以帮助我
答案 0 :(得分:2)
这不起作用,因为:
您必须将图像写入可公开访问的Bitmap文件并将路径传递给该文件,或实现ContentProvider。