2

Whatsappで写真を送信したい. Whatsapp で画像チューザーを選択すると、アプリが起動します。インテントの結果を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;
}
4

1 に答える 1

0

このコードを使用して画像を送信できました

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"));
于 2014-09-12T19:29:48.623 に答える