仅在android中使用Intent通过电子邮件共享
我想只通过电子邮件发送照片使用意图。我使用下面的代码,但它不仅打开gmail,但显示了许多股票期权 请帮我分享唯一的gmail仅在android中使用Intent通过电子邮件共享,android,android-intent,Android,Android Intent,我想只通过电子邮件发送照片使用意图。我使用下面的代码,但它不仅打开gmail,但显示了许多股票期权 请帮我分享唯一的gmail Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/jpeg"); // put here your mime type List<ResolveInfo> resInfo = getPackageManager().queryIntentAc
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg"); // put here your mime type
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if(!resInfo.isEmpty()) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
ArrayList<Uri> uris = new ArrayList<Uri>();
for (ResolveInfo info : resInfo) {
if(info.activityInfo.packageName.toLowerCase().contains("gmail") || info.activityInfo.name.toLowerCase().contains("gmail")) {
targetedShare.setType("image/jpeg"); // put here your mime type
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Amplimesh Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT,"Attached the Quote");
//Fetching the Installed App and open the Gmail App.
for(int index = 0; index < productList.size(); index++) {
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(productList.get(index).getOverlayBitmap());
Bitmap overLayBitmap = BitmapFactory.decodeStream(byteInputStream);
String fileName = SystemClock.currentThreadTimeMillis() + ".png";
//Save the bitmap to cache.
boolean isSaved = Helper.saveImageToExternalStorage(overLayBitmap, getApplicationContext(), fileName);
if(isSaved)
uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/amplimesh/images/" + fileName)));
}
}
}
targetedShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(targetedShare, "Sending multiple attachment"), 12345);
}
你不能只得到gmail。但您可以针对某些内容类型的应用程序
试试这个
intent.setType("message/rfc822");
对我来说,它起作用了。。
尝试Intent.ACTION\u SENDTO
这就是方法
public void emailShare()
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
emailIntent.setType("image/jpeg");
//File bitmapFile = new File(Environment.getExternalStorageDirectory()+"DCIM/Camera/img.jpg");
//myUri = Uri.fromFile(bitmapFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/DCIM/Camera/img.jpg"));
emailIntent.setData(Uri.parse("mailto:"));
startActivityForResult(Intent.createChooser(emailIntent, "Complete action using:"),PICK_CONTACT_REQUEST);
}
startActivityForResult将返回结果。如果邮件发送成功,则MESSAGE_RESULT是预期的结果
了解结果
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == MESSAGE_RESULT) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "E-Mail sent successfully", Toast.LENGTH_LONG).show();
}
}
}
声明静态最终int消息_RESULT=1;一开始
希望有帮助。试试这个:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_BODY);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fileName));
startActivity(Intent.createChooser(emailIntent, "Sharing Options"));
只使用gmail应用程序不是一个好主意。因为有很多手机没有安装gmail应用程序。尝试此代码,它将显示所有可以发送电子邮件的应用程序。我确信它不会显示你手机上的所有共享应用程序。但它将展示其他一些可以处理任何共享意图的应用程序。像谷歌硬盘一样。使用Intent.ACTION\u视图代替Intent.ACTION\u发送
或者您可以使用:
startActivity(intent);
跟随这个@SanketKachhela,它会显示许多选项,如Skype、Gmail、Office Suite wifi Direct。我只想在gmail上分享。@user2695306所以。。。你必须在你的清单文件中给出一个具体的意图行动。@piyusgupta请帮助我如何才能做到这两点。。。1.您正在使用startActivityForResult…-我可能错了,但我不确定GMail应用程序是否会返回结果。2.不过,最主要的一点是,您使用的是Intent.createChooser,顾名思义,它将自动创建已安装应用程序的列表,这些应用程序已注册,可在特定mime类型上执行特定操作。我不想只在选项中获取gmail。我想直接打开带有附件的gmail应用程序。通过在gmail中明确指定撰写活动,你只能获得gmail,但除此之外,我同意@SanketKachhela*特别使用类名是愚蠢的,因为不是每个用户都会有gmail,撰写活动类名可以从版本更改为version@ataulm我如何在intent中指定类名,以便它只提供选项gmail。请help@user2695306注意,由于我之前评论中的原因,它是没有文档记录的,而且很愚蠢,也许还有更多
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "Subject" + "&body=" + "Body" + "&to=" + "email@mail.com");
intent.setData(data);
startActivity(Intent.createChooser(intent, "Choose app"));
startActivity(intent);