[英]Sending picture in Whatsapp
I want to send a picture in Whatsapp. 我想在Whatsapp中发送图片。 My App starts when I select the Image chooser in Whatsapp. 当我在Whatsapp中选择图像选择器时,我的应用程序启动。 How can I send the result of the Intent back to whatsapp? 如何将Intent的结果发送回whatsapp?
I use the following Code: 我使用以下代码:
// 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;
}
I was able to send image using this code 我可以使用此代码发送图像
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"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.