Java 如何通过 Viber 消息从 Android 应用程序发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19683297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send message from Android app through Viber message
提问by vonbk
I want to write small Android app to send the message through Viber to people whom are listed in my contact list. But I could not find any sample code to do this task. If you know how to do this task.
我想编写一个小的 Android 应用程序,通过 Viber 将消息发送给我的联系人列表中列出的人。但是我找不到任何示例代码来执行此任务。如果您知道如何执行此任务。
Please teach me.
请教我。
Vonbk
冯布克
回答by Rethinavel
If viber application is installed in your device, You can call an intent to share the text.
如果您的设备中安装了 viber 应用程序,您可以调用一个意图来共享文本。
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = context.getPackageManager()
.queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase(
Locale.getDefault()).contains("com.viber.voip")
|| info.activityInfo.name.toLowerCase(
Locale.getDefault()).contains("com.viber.voip")) {
share.putExtra(Intent.EXTRA_TEXT, "Your text to share");
share.setPackage(info.activityInfo.packageName);
found = true;
context.startActivity(Intent.createChooser(share, "Select"));
break;
}
}
if (!found) {
displayToast(context, "Install viber android application");
Uri marketUri = Uri.parse("market://details?id="
+ "com.viber.voip");
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
context.startActivity(marketIntent);
}
}
I am not sure it will work. But it will worth a shot.
我不确定它会起作用。但这值得一试。
You can also share with the plain intent which asks the user to select and share :
您还可以与要求用户选择和共享的简单意图共享:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));