Android通话问题

时间:2011-05-22 11:55:39

标签: android phone-call

我正在使用下面的代码,但我的app力独立关闭哪一个使用。这些来自网上发现的几个例子,但它们都没有起作用:

semes2变量是从ContactsContract检索到的电话号码,不为空(由Toast msg验证)。

Uri uri = Uri.fromParts("tel", semes2, null);
Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);

Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:6365551212"));
startActivity(dialIntent);

Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + semes2)); 
dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialIntent);

在清单中我有<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

我缺少什么?

编辑:logcat:

05-24 05:46:17.404: ERROR/AndroidRuntime(272): FATAL EXCEPTION: main
05-24 05:46:17.404: ERROR/AndroidRuntime(272): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel://+36301111111 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43f8e500 272:com.bfarago.nevnap/10048} (pid=272, uid=10048) requires android.permission.CALL_PHONE
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.os.Parcel.readException(Parcel.java:1247)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.os.Parcel.readException(Parcel.java:1235)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.app.Activity.startActivityForResult(Activity.java:2817)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.app.Activity.startActivity(Activity.java:2923)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at com.bfarago.nevnap.MainActivity$1$1$1.onClick(MainActivity.java:1363)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.widget.ListView.performItemClick(ListView.java:3382)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.os.Handler.handleCallback(Handler.java:587)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.os.Looper.loop(Looper.java:123)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at java.lang.reflect.Method.invokeNative(Native Method)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at java.lang.reflect.Method.invoke(Method.java:521)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-24 05:46:17.404: ERROR/AndroidRuntime(272):     at dalvik.system.NativeStart.main(Native Method)
05-24 05:46:17.564: WARN/ActivityManager(58):   Force finishing activity com.bfarago.nevnap/.MainActivity
05-24 05:46:18.224: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:19.754: INFO/Process(272): Sending signal. PID: 272 SIG: 9
05-24 05:46:19.816: INFO/ActivityManager(58): Process com.bfarago.nevnap (pid 272) has died.
05-24 05:46:19.844: WARN/ActivityManager(58): Scheduling restart of crashed service com.bfarago.nevnap/.UpdateService in 5000ms
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{43fac220 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{440383a8 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.954: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 272 uid 10048
05-24 05:46:21.110: WARN/NotificationService(58): Object died trying to hide notification android.app.ITransientNotification$Stub$Proxy@43edd2c0 in package com.bfarago.nevnap
05-24 05:46:21.114: WARN/ActivityManager(58): setProcessForeground called on unknown pid: 272
05-24 05:46:24.944: INFO/ActivityManager(58): Start proc com.bfarago.nevnap for service com.bfarago.nevnap/.UpdateService: pid=286 uid=10048 gids={1015}
05-24 05:46:29.200: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:30.605: DEBUG/dalvikvm(162): GC_EXPLICIT freed 2438 objects / 143352 bytes in 192ms

2 个答案:

答案 0 :(得分:0)

找到解决方案。而不是ACTION_CALL我应该使用ACTION_DIAL。我也可以在tel:之后删除//,这没关系。例如,

Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + semes2));
startActivity(intent);

然而,第二个例子仍然强制关闭,即使它有动作拨号。

答案 1 :(得分:0)

您应该在Android清单文件中包含以下权限android.permission.CALL_PHONE:

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