如何从Android应用程序启动Viber的电话吗?(How to start Viber call

2019-09-02 07:16发布

我正在开发一个Android应用程序,以及除了其他功能它必须能够把使用Viber的通话。 我试图用解决方案适用于Skype ,但没有成功。 错误,我得到的是:

05-08 19:51:51.660: D/AndroidRuntime(29140): Shutting down VM
05-08 19:51:51.660: W/dalvikvm(29140): threadid=1: thread exiting with uncaught exception (group=0x40018578)
05-08 19:51:51.680: E/AndroidRuntime(29140): FATAL EXCEPTION: main
05-08 19:51:51.680: E/AndroidRuntime(29140): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=viber:0692155555 }
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.app.Activity.startActivityForResult(Activity.java:2827)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.app.Activity.startActivity(Activity.java:2933)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at rs.stanar.pantaxinovisad.MainActivity.call(MainActivity.java:61)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at rs.stanar.pantaxinovisad.MainActivity.onClick(MainActivity.java:117)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.view.View.performClick(View.java:2485)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.view.View$PerformClick.run(View.java:9080)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.os.Handler.handleCallback(Handler.java:587)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.os.Looper.loop(Looper.java:130)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at android.app.ActivityThread.main(ActivityThread.java:3687)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at java.lang.reflect.Method.invoke(Method.java:507)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-08 19:51:51.680: E/AndroidRuntime(29140):    at dalvik.system.NativeStart.main(Native Method)

我的应用程序,我想用它来调用Viber的是代码:

public void call(String dialNumber) {
        Intent viber = new Intent("android.intent.action.VIEW");
        viber.setData(Uri.parse("viber:" + dialNumber));
        startActivity(viber);
    }

  <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="viber" />
        </intent-filter>
        <intent-filter
            android:priority="0" >
            <action android:name="android.intent.action.CALL_PRIVILEGED" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="tel" />
        </intent-filter>

我应该为了使这项工作呢?

Answer 1:

这个问题与这一段代码解决:

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);
    }
}

在那里,这是至关重要的:“android.intent.action.CALL_PRIVILEGED”

应用此后,新的窗口被打开祭由用于放置呼叫的所有可能的方法来制备呼叫 - 在此特定情况下,它们是拨号器和Viber的和Skype(或后来添加的任何其它方法)。



Answer 2:

如果你想开始明确的Viber拨打特定电话号码:

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);

所有你需要做的是要初始化变量phone_number_to_call。



文章来源: How to start Viber call from an Android app?