问题
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
回答1:
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")))
}
}
回答2:
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)
)
);
}
}
}
来源:https://stackoverflow.com/questions/27189221/how-to-open-viber-public-chat-from-android-app