将应用中的图像附加到Gmail和共享

时间:2015-05-25 07:20:23

标签: android

我想仅使用GET从应用分享我的图片。 这是我的代码:

gmail

i am getting all the sharing app, i want gmail to open with my image attached to it

如何修改我的代码

3 个答案:

答案 0 :(得分:0)

此方法允许您共享单个应用程序的数据。

      public void share(String nameApp, String imagePath, String message) {
        try {
            List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
           share.putExtra(Intent.EXTRA_EMAIL,`enter code here`
            new String[] { "bipush.osti@gmail.com" });
          share.putExtra(Intent.EXTRA_SUBJECT, "subject");
          share.putExtra(Intent.EXTRA_TEXT, "compose mail");
            List<ResolveInfo> resInfo = getPackageManager()
                    .queryIntentActivities(share, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(
                            android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg"); // put here your mime
                                                            // type
                    if (info.activityInfo.packageName.toLowerCase().contains(
                            nameApp)
                            || info.activityInfo.name.toLowerCase().contains(
                                    nameApp)) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT,
                                "Sample Photo");
                        targetedShare.putExtra(Intent.EXTRA_TEXT, message);
                        targetedShare.putExtra(Intent.EXTRA_STREAM,
                                Uri.fromFile(new File(imagePath)));
                        targetedShare.setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(
                        targetedShareIntents.remove(0), "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[] {}));
                startActivity(chooserIntent);
            }
        } catch (Exception e) {
            Log.v("VM",
                    "Exception while sending image on" + nameApp + " "
                            + e.getMessage());
        }
    }

例如,您可以使用。

分享gmail的图片
File filePath = new File("your image path");
share("gmail",filePath.toString(),"your comment");

您只需更改名称即可与其他应用程序共享。

share("facebook",filePath.toString(),"your comment");
share("twitter",filePath.toString(),"your comment");

答案 1 :(得分:0)

尝试设置message/rfc822而不是image/png

答案 2 :(得分:0)

您必须提及要处理它的应用程序的包名称。要通过Gmail应用程序发送,请添加以下行

sharingIntent.setPackage("com.google.android.gm");