我想编写一个小型Android应用程序,通过Viber 将消息发送给我的联系人列表中的人员。但我找不到 任何示例代码来完成此任务。 如果你知道如何完成这项任务。如何通过Viber消息从Android应用程序发送消息
请教我。
Vonbk
我想编写一个小型Android应用程序,通过Viber 将消息发送给我的联系人列表中的人员。但我找不到 任何示例代码来完成此任务。 如果你知道如何完成这项任务。如何通过Viber消息从Android应用程序发送消息
请教我。
Vonbk
如果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);
}
}
我不确定它会起作用。但它值得一试。
您还可以询问用户选择普通的意图和分享分享:
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"));
使用意图和Viber的将收到您的申请 –
你解决问题了吗? viber如何在不要求选择电话号码的情况下将消息发送到“xxxx”号码? –