1

我想使用Viber'sIntent for Android。

我正在尝试使用以下代码来实现它,但它不起作用。

Intent intent = new intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String text = MyOutputText.getText().toString();              
intent.setPackage("com.viber");

谁能告诉我哪里出错了?

这是我的错误日志:


06-05 15:16:27.495: E/AndroidRuntime(29956): FATAL EXCEPTION: main
06-05 15:16:27.495: E/AndroidRuntime(29956): android.content.ActivityNotFoundException: No Activity found to handle Intent {     act=android.intent.action.SEND typ=text/plain pkg=com.viber }
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1535)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.app.Activity.startActivityForResult(Activity.java:3195)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.app.Activity.startActivity(Activity.java:3302)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at com.translate.AndroidTranslate$5.onClick(AndroidTranslate.java:174)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.view.View.performClick(View.java:3627)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.view.View$PerformClick.run(View.java:14329)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.os.Handler.handleCallback(Handler.java:605)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.os.Looper.loop(Looper.java:137)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at android.app.ActivityThread.main(ActivityThread.java:4511)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at java.lang.reflect.Method.invokeNative(Native Method)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at java.lang.reflect.Method.invoke(Method.java:511)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
06-05 15:16:27.495: E/AndroidRuntime(29956):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1
Intent intent = new intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String text = MyOutputText.getText().toString();              
intent.setPackage("com.viber");

//添加这个

startActivity(intent);
于 2013-06-04T11:17:45.810 回答
0

您可以使用此代码通过 Viber 发送简单的文本,Viber 将引导您选择收件人:

Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setPackage("com.viber.voip");
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "Your text to share");
MainActivity.this.startActivity(share);
于 2015-04-05T10:00:28.340 回答
0

您设置的包名称错误,它应该是com.viber.voip.

如果您想传入 phoneNumber 作为参数以使用 Intent Uri 的用户电话号码启动 Viber,请查看此答案。

https://stackoverflow.com/a/61221029/2867351

于 2020-04-15T03:52:58.100 回答