von*_*nbk 8 java android viber
我想编写小型Android应用程序,通过Viber将消息发送给我的联系人列表中列出的人.但我找不到任何示例代码来执行此任务.如果你知道如何完成这项任务.
请教我.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定它会起作用。但值得一试。
您还可以以简单的意图进行共享,要求用户选择并共享:

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"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11012 次 |
| 最近记录: |