Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Viber public chat from Android app

Tags:

android

viber

I know how to open a conversation with a number in Viber: How to start Viber call from an Android app [new version]?

But how do I open a public chat? Any ideas?

Thanks in advance

like image 598
Erick Filho Avatar asked Nov 28 '14 12:11

Erick Filho


People also ask

How can I open Viber flutter?

launch('viber://chat?number=$phoneNumber'); If you want to open the conversation with a predefined text, you can write like this: launch('viber://chat/?number=$phoneNumber&draft=$yourMessage'); Please note, if Viber is not installed on your device, the launch method throws an error.


2 Answers

this Kotlin code works fine for me

        val viberPackageName = "com.viber.voip"
        val phone= "5757575757"

        try {
            activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("viber://add?number=$phone")))
        } catch (ex: ActivityNotFoundException) {
            try {
                activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$viberPackageName")))
            } catch (ex: ActivityNotFoundException) {
                activity?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$viberPackageName")))
            }
        }
like image 90
Stanislav Tkach Avatar answered Oct 29 '22 08:10

Stanislav Tkach


Java code

  public void addViberNumber(Context context,String phone) {
    String viberPackageName = "com.viber.voip";

    try {
        context.startActivity(new
                        Intent(Intent.ACTION_VIEW,
                        Uri.parse("viber://add?number="+phone)
                )
        );
    } catch (ActivityNotFoundException ex) {
        try {
            context.startActivity
                    (new Intent(Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=+" + viberPackageName))
                    );
        } catch (ActivityNotFoundException exe) {
            context.startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + viberPackageName)
                    )
            );
        }
    }
}
like image 34
Falah H. Abbas Avatar answered Oct 29 '22 09:10

Falah H. Abbas