1

我想使用 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().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);
}
4

5 回答 5

2

You can not get only gmail. but you can target some content type application.

try this

intent.setType("message/rfc822");
于 2013-08-24T06:17:15.640 回答
0

对我来说它的工作..尝试 Intent.ACTION_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();
        }
    }

}

在开头声明static final int MESSAGE_RESULT = 1;

希望能帮助到你。

于 2013-08-24T06:30:41.277 回答
0

使用Intent.ACTION_VIEWinsted ofIntent.ACTION_SEND

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);
于 2014-05-20T08:32:38.920 回答
0

尝试这个:

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"));
于 2013-08-24T06:45:46.980 回答
-2
    String shareImageLocation="Image file address";//Give file address here
Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL,
        new String[] { "someone@someone.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "Send photos");
i.putExtra(Intent.EXTRA_STREAM, shareImageLocation);
String bugReportBody = description;
i.putExtra(Intent.EXTRA_TEXT, bugReportBody);
ArrayList<Uri> uris = new ArrayList<Uri>();
File fileIn = new File(shareImageLocation);
uris.add(Uri.fromFile(fileIn));
i.putExtra(Intent.EXTRA_STREAM, uris);
try {
    startActivityForResult(
            Intent.createChooser(i, "Complete action using"),
            SEND_EMAIL);
} catch (android.content.ActivityNotFoundException ex) {
}

只使用 gmail 应用程序不是一个好主意。因为有很多手机没有安装 gmail 应用程序。试试这个代码,它将显示所有可以发送电子邮件的应用程序。我确定它不会显示您手机中的所有共享应用程序。但它会显示其他一些可以处理任何共享意图的应用程序。就像谷歌驱动器。

于 2013-08-24T07:02:55.740 回答