1

我正在尝试设计一个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);
    }

这是我到目前为止所尝试的。是否可以在 localhost 上进行测试?我没有得到想要的结果。这是我的日志猫。

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
4

2 回答 2

2

电话

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>   
于 2013-04-06T06:43:01.937 回答
1

您是否授予了 CALL_PHONE 权限?如果没有,则在清单文件中添加以下权限

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

其次,参数 toUri.parse("myNumber")应该以“tel:”前缀开头,所以说如果号码是 1234,那么对 Uri.parse 的调用应该是Uri.parse("tel: " + "myNumber")

于 2013-04-06T06:43:27.300 回答