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

gmailだけは取得できません。ただし、一部のコンテンツ タイプのアプリケーションをターゲットにすることはできます。

これを試して

intent.setType("message/rfc822");
于 2013-08-24T06:17:15.640 に答える
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 に答える
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_VIEW代わりに使うIntent.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 に答える