1

I want to use Viber's Intent for Android.

I am trying to implement that using the following code, but it is not working.

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

Can anyone tell me where I am going wrong?

Here is my error Log:


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)
Nadeem Iqbal
  • 2,357
  • 1
  • 28
  • 43
user1737035
  • 11
  • 1
  • 4
  • The code you show is only setting up your intent. Are you using [startActivity (Intent intent)](http://developer.android.com/reference/android/app/Activity.html#startActivity%28android.content.Intent%29) to actually try to start Viber with that intent? If so, what kind of error are you seeing? You might also want to look at startActivityForResult, depending on your needs. – Rafe Jun 04 '13 at 11:12
  • If you want to place a call with Viber, you might be interested in this question: http://stackoverflow.com/questions/16447148/how-to-start-viber-call-from-an-android-app – zbr Jun 04 '13 at 11:13
  • @Rafe.. can you please explain a little how can i use startActivityForResult, My need is to send message using viber. I dont want to make call from Viber. Did you get it? – user1737035 Jun 05 '13 at 10:13

3 Answers3

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

//Add this

startActivity(intent);
Jibran Khan
  • 3,236
  • 4
  • 37
  • 50
0

you can use this code to send a simple text via Viber, Viber will guide you to select recipient:

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);
Dmila Ram
  • 1,054
  • 1
  • 13
  • 19
0

You've set the package name wrong, it's supposed to be com.viber.voip.

Checkout this answer, if you want to passed in a phoneNumber as a parameter to launch the Viber with the user phone number with Intent Uri.

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

Morgan Koh
  • 2,297
  • 24
  • 24