我成功地使用此代码将文本发送到特定的WhatsApp联系人
private void openWhatsApp(String mobileNumber) {
String text = "Hi";
if(whatsappInstalledOrNot("com.whatsapp")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("whatsapp://send?text="+text+ "&phone="+mobileNumber));
startActivity(browserIntent);
}else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
现在,我想与文本共享ImageFile。我有了文件路径,但不知道如何放入该浏览器。请帮助。
我知道回答为时已晚,但没有人想知道。这是您可以使用意图在WhatsApp上共享图像文件
Intent share = new Intent();
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = file; // here path to your image file
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
Log.e("media", String.valueOf(uri));
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(share);
ps注意:当我尝试过一些但未能实现的情况下,您不能用文本发送图像,但是您只能从上面的代码共享图像文件