How to start a Viber call from an Android application [new version]?

Some time ago I created this post, and my colleague and I found two different answers to it (both of them worked):

  • The first solution was to use

    Intent callIntent = new Intention ("android.intent.action.CALL_PRIVILEGED");

    which will open a new window offer for a call made by all possible ways of placing a call - in this particular case they were Dialer and Viber and Skype (or any other method added later).

  • The second solution was to explicitly call Viber and put a telephone number, which would also be called

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

Since the last Viber update (we noticed this yesterday), none of these methods have worked. At first, you simply make a Skype call without even offering Dialer (!?!), But if Skype is not installed, it will return to Dialer and place the call. Secondly, a crash stating that there is no activity to work with Intent?

Any idea what is going on and how can this be solved?

The error log is as follows:

01-27 17:35:03.794: E/AndroidRuntime(7738): FATAL EXCEPTION: main 01-27 17:35:03.794: E/AndroidRuntime(7738): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.viber.voip dat=tel:xxxxxxxxx (has extras) } 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Activity.startActivityForResult(Activity.java:3388) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Activity.startActivityForResult(Activity.java:3349) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Activity.startActivity(Activity.java:3584) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.Activity.startActivity(Activity.java:3552) 01-27 17:35:03.794: E/AndroidRuntime(7738): at rs.limitline.maxitaxins.MainActivity.callViber(MainActivity.java:96) 01-27 17:35:03.794: E/AndroidRuntime(7738): at rs.limitline.maxitaxins.MainActivity.onClick(MainActivity.java:186) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.view.View.performClick(View.java:4212) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.view.View$PerformClick.run(View.java:17476) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.os.Handler.handleCallback(Handler.java:800) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.os.Handler.dispatchMessage(Handler.java:100) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.os.Looper.loop(Looper.java:194) 01-27 17:35:03.794: E/AndroidRuntime(7738): at android.app.ActivityThread.main(ActivityThread.java:5431) 01-27 17:35:03.794: E/AndroidRuntime(7738): at java.lang.reflect.Method.invokeNative(Native Method) 01-27 17:35:03.794: E/AndroidRuntime(7738): at java.lang.reflect.Method.invoke(Method.java:525) 01-27 17:35:03.794: E/AndroidRuntime(7738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 01-27 17:35:03.794: E/AndroidRuntime(7738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 01-27 17:35:03.794: E/AndroidRuntime(7738): at dalvik.system.NativeStart.main(Native Method) 

[UPDATE] This also indicates an error:

 01-27 19:46:56.704: D/Greska(19822): Permission Denial: starting Intent { act=com.viber.voip.action.CALL dat=tel:xxxxxxxxx cmp=com.viber.voip/com.viber.service.OutgoingCallBroadcaster (has extras) } from ProcessRecord{416c41b8 19822:rs.limitline.maxitaxins/u0a10065} (pid=19822, uid=10065) not exported from uid 10147 
+6
source share
2 answers

According to the Viber manifest, there is activity "com.viber.voip.phone.PhoneActivity", which is responsible for the action "com.viber.voip.action.CALL". In the new version of Viber (4.2.1.1) this activity is marked by android: exported = "false" . As a result of this, it is impossible to start this activity from external applications ...

Edit

This code opens the welcome screen for the specified contact.

 String sphone = "12345678"; Uri uri = Uri.parse("tel:" + Uri.encode(sphone)); Intent intent = new Intent("android.intent.action.VIEW"); intent.setClassName("com.viber.voip", "com.viber.voip.WelcomeActivity"); intent.setData(uri); context.startActivity(intent); 

but the user must click the β€œfree call” button to start the call.

+16
source

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" /> 
+3
source

All Articles