【问题标题】:how to share images from my app to whatsapp?如何将图像从我的应用程序共享到 whatsapp?
【发布时间】:2017-09-22 12:22:12
【问题描述】:

我在这里将图像从我的应用程序共享到 whatsapp。但是此代码仅适用于 mylist1[i],不适用于 mylist2[i] 和 mylist3[i]。在我的活动文件中,每个列表中有 15 张图片。怎么办?

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.example.drawcelebrities/"+mylist1[i]+mylist2[i]+mylist3[i]);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share via"));

【问题讨论】:

标签: android share


【解决方案1】:

在 mylist[] 中获取图像数组并使用以下代码,然后通过 whatsapp 共享图像。

Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+mylist[i]);

Intent shareIntent = new Intent();
             shareIntent.setAction(Intent.ACTION_SEND);
             shareIntent.setType("image/*");
             shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
             startActivity(Intent.createChooser(shareIntent, "Share via"));

【讨论】:

    【解决方案2】:

    如果我没记错的话,那么你应该使用android.content.Intent.ACTION_SEND_MULTIPLE..参考这个link它会帮助你..

    【讨论】:

      【解决方案3】:
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_SEND_MULTIPLE);
      intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
      intent.setType("image/jpeg");
      ArrayList<Uri> files = new ArrayList<Uri>();
      for(String path : filesToSend /* List of the files you want to send */) {
      File file = new File(path);
       Uri uri = Uri.fromFile(file);
      files.add(uri);
      }
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
      startActivity(intent);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-25
        • 1970-01-01
        相关资源
        最近更新 更多