How to start Viber call from an Android app?

こ雲淡風輕ζ 提交于 2019-11-28 08:49:19

This problem was resolved with this piece of code:

public void call(String dialNumber) {
    try{
    Intent callIntent = new Intent("android.intent.action.CALL_PRIVILEGED");
    callIntent.setData(Uri.parse("tel:" + dialNumber));
    startActivity(callIntent);
    }
    catch (Exception e) {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + dialNumber));
        startActivity(callIntent);
    }
}

where this was crucial: "android.intent.action.CALL_PRIVILEGED"

After applying this, new window was opened offering for call to be made by all possible means for placing call - in this particular case, they were Dialer and Viber and Skype (or any other method added later).

If you want to start Viber explicitly to call specific phone number:

Intent localIntent4 = new Intent("com.viber.voip.action.CALL");
localIntent4.setType("vnd.android.cursor.item/vnd.com.viber.voip.call");
localIntent4.setData(Uri.parse("tel:" + phone_number_to_call));
localIntent4.putExtra("external_call", true);
localIntent4.putExtra("contact_id", -1L);
startActivity(localIntent4);

All you need to do is to initialize variable phone_number_to_call as you wish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!