You can call per Viber direct (without WelcomeActivity), but the user must have this number in Contacts.
public void callToViberContact(String phoneNumber, Context context) { Uri uri = getUriFromPhoneNumber(phoneNumber, context); if (uri != null) { Intent intent = new Intent("android.intent.action.VIEW"); intent.setClassName("com.viber.voip", "com.viber.voip.SystemDialogActivityPublic"); intent.setData(uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { Toast.makeText(context, "Number is not in Viber Contacts List", Toast.LENGTH_LONG).show(); } } private Uri getUriFromPhoneNumber(String phoneNumber, Context context) { Uri uri = null; String contactId = getContactIdByPhoneNumber(phoneNumber, context); if (!TextUtils.isEmpty(contactId)) { Cursor cursor = context.getContentResolver().query( ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._ID}, ContactsContract.Data.DATA2 + "=? AND " + ContactsContract.Data.CONTACT_ID + " = ?", new String[]{"Viber", contactId}, null); if (cursor != null) { while (cursor.moveToNext()){ String id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Data._ID)); if (!TextUtils.isEmpty(id)) { uri = Uri.parse(ContactsContract.Data.CONTENT_URI + "/" + id); break; } } cursor.close(); } } return uri; } private String getContactIdByPhoneNumber(String phoneNumber, Context context) { ContentResolver contentResolver = context.getContentResolver(); String contactId = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] projection = new String[]{ContactsContract.PhoneLookup._ID}; Cursor cursor = contentResolver.query( uri, projection, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { contactId = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)); } cursor.close(); } return contactId; }
READ_CONTACTS permission required. Remember to add to the manifest:
<uses-permission android:name="android.permission.READ_CONTACTS" />
jlga source share