How to send message from Android app through Viber message
Asked Answered
G

1

8

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.

Please teach me.

Vonbk

Granthem answered 30/10, 2013 at 13:15 Comment(2)
Use intents and viber will receive your requestSultan
Did you solved your problem? How can viber send message to "xxxx" number without asking to select phone number?Straw
R
3

If viber application is installed in your device, You can call an intent to share the text.

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 :

Like this

         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"));
Rockhampton answered 30/10, 2013 at 13:42 Comment(8)
Hi Rethinavel Velu, How can I specify the outgoing phone number. I added : share.putExtra(Intent.EXTRA_PHONE_NUMBER,"xxxxxx"); But it does not work well.Granthem
What do you mean by specifying outgoing number..? You want to share the phone number to viber or what?Rockhampton
I meant that I want to send message ""Your text to share" to my friend whom has phone number is "xxxxxxx".Granthem
Viber will ask you to do so, I believe. I think you will send directly. I am not sure about that. Let me check and revert you backRockhampton
Yes, Viber asked me to do so as you said. But it is not my expectation. I want to Viber send message to "xxxx" number without asking me to select phone number. On other hand, I want Viber has same function as following SMS code: smsManager.sendMultipartTextMessage("xxxxxx", null, messageArray, null,null);Granthem
Oh i see. I don't know how to implicitly send a number.Rockhampton
Thank you so much for your effort constantly.Granthem
@Granthem did you find any way to send number to viber ?Permittivity

© 2022 - 2024 — McMap. All rights reserved.