我正在尝试设计一个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上测试?我没有得到理想的结果。这是我的logcat。
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
答案 0 :(得分: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>
答案 1 :(得分:1)
您是否已获得CALL_PHONE权限?如果没有,则在清单文件中添加以下持久性
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
其次,Uri.parse("myNumber")
的参数应该以“tel:”前缀开头,所以如果数字是1234,那么调用Uri.parse应该是Uri.parse("tel: " + "myNumber")