本文介绍了在 Android 的 Whatsapp 上分享文字或图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,我必须在其中与我的应用程序共享 WhatsApp 上的图像和文本.
I am developing an application in which i have to share image and text on WhatsApp with in my application.
在IOS我有这个代码
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!&abid=143rnjk4545352523"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
我将如何在 Android 中执行此操作?是否可以从 Android 应用程序在 whatsapp 上共享文本和图像?
How i will be able to do this in Android?Is there any possiblity to share text and images on whatsapp from Android app?
推荐答案
您可以使用 Whatsapp intent 来做到这一点.
You can use Whatsapp intent to do so.
注意:- WhatsApp 不支持图片和文字的消息,所以使用下面的代码来分享文字.
Note :- WhatsApp does not support messages with both pictures and text,so use below code to share text.
在 Whatsapp 上分享文字
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Hello World");
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
在 Whatsapp 上分享图片
Intent whatsappIntent = new Intent(android.content.Intent.ACTION_SEND);
whatsappIntent.setType("image/*");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file));//add image path
startActivity(Intent.createChooser(share, "Share image using"));
更新
Whatsapp 现在支持带有图像的文本(视为图像标题)
Whatsapp now support text (consider as image caption) with image as
Intent whatsappIntent = new Intent(android.content.Intent.ACTION_SEND);
whatsappIntent.setType("image/*");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Hello World");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); //add image path
startActivity(Intent.createChooser(share, "Share image using"));
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(activity, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
这篇关于在 Android 的 Whatsapp 上分享文字或图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!