【问题标题】:Sending picture in Whatsapp在 Whatsapp 中发送图片
【发布时间】:2013-03-25 13:53:42
【问题描述】:

我想在 Whatsapp 中发送图片。当我在 Whatsapp 中选择图像选择器时,我的应用程序就会启动。如何将 Intent 的结果发送回 whatsapp?

我使用以下代码:

         // on button press
            String path = SaveCache(R.drawable.pic_1);

            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/*");
            share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));  


        }

}


private String SaveCache(int resID) {
    String path = "";  
    try {
        InputStream is = getResources().openRawResource(resID);
        File cacheDir = context.getExternalCacheDir();
        File downloadingMediaFile = new File(cacheDir, "abc.jpg");
        byte[] buf = new byte[256];
        FileOutputStream out = new FileOutputStream(downloadingMediaFile);   
        while (true) {
            int rd = is.read(buf, 0, 256);
            if (rd == -1 || rd == 0)
                break;
            out.write(buf, 0, rd);              
        }
        is.close();
        out.close();
        return downloadingMediaFile.getPath();
    } catch (Exception ex) {

        ex.printStackTrace();
    }
    return path;
}

【问题讨论】:

    标签: android image android-intent android-gallery whatsapp


    【解决方案1】:

    我可以使用此代码发送图像

    Uri uri = Uri.parse("android.resource://com.example.test/drawable/image_1");
                    sharingIntent.setType("image/jpg"); 
                    sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); 
                    startActivity(Intent.createChooser(sharingIntent, "Share image using"));
    

    【讨论】:

      猜你喜欢
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 2016-07-02
      • 1970-01-01
      • 2017-11-11
      相关资源
      最近更新 更多