Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

skype - How to start Viber call from an Android app?

I am developing an Android application, and besides other functionalities it has to be able to place a call using Viber. I tried to use solution for Skype but without success. Error which I get is:

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)

Code of my app that I am trying to use to invoke Viber is:

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>

What should I do in order to make this work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...