我正在尝试设计一个android系统,可以在其中拨打我希望的电话号码。我有一个面向患者的界面,在我的界面中,我放置了一个用于紧急呼叫医生的按钮,如果他们开始感到恶心,则只需单击一下按钮,便会呼叫医生。

public void callDoc(View v)
    {
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("myNumber"));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        startActivity(intent);
    }


到目前为止,这是我尝试过的。是否可以在本地主机上对此进行测试?我没有得到理想的结果。这是我的日志。

04-06 11:07:16.925: W/dalvikvm(1786): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-06 11:07:16.965: E/AndroidRuntime(1786): FATAL EXCEPTION: main
04-06 11:07:16.965: E/AndroidRuntime(1786): java.lang.IllegalStateException: Could not execute method of the activity
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.view.View$1.onClick(View.java:2144)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.view.View.performClick(View.java:2485)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.view.View$PerformClick.run(View.java:9080)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.os.Handler.handleCallback(Handler.java:587)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.os.Looper.loop(Looper.java:130)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at java.lang.reflect.Method.invokeNative(Native Method)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at java.lang.reflect.Method.invoke(Method.java:507)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at dalvik.system.NativeStart.main(Native Method)
04-06 11:07:16.965: E/AndroidRuntime(1786): Caused by: java.lang.reflect.InvocationTargetException
04-06 11:07:16.965: E/AndroidRuntime(1786):     at java.lang.reflect.Method.invokeNative(Native Method)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at java.lang.reflect.Method.invoke(Method.java:507)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.view.View$1.onClick(View.java:2139)
04-06 11:07:16.965: E/AndroidRuntime(1786):     ... 11 more
04-06 11:07:16.965: E/AndroidRuntime(1786): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=03325465573 flg=0x10040000 }
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.app.Activity.startActivityForResult(Activity.java:2827)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at android.app.Activity.startActivity(Activity.java:2933)
04-06 11:07:16.965: E/AndroidRuntime(1786):     at com.edps.EmergencyActivity.callDoc(EmergencyActivity.java:22)
04-06 11:07:16.965: E/AndroidRuntime(1786):     ... 14 more
04-06 11:07:19.613: I/Process(1786): Sending signal. PID: 1786 SIG: 9

最佳答案

tel

String number = "23454568678";
    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:" +number));
    startActivity(intent);


使用许可

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

关于android - 紧急调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15847830/

10-10 10:22