当我尝试拨打电话时强制关闭

时间:2011-08-27 12:29:14

标签: android android-intent permissions phone-call

我正在尝试点击列表项目的电话。

这是onclick监听器的代码:

    lv.setOnItemClickListener(new OnItemClickListener() { 
         public void onItemClick(AdapterView<?> parent, View view, 
             int position, long id) { 

             Intent intent = new Intent(Intent.ACTION_CALL);

             intent.setData(Uri.parse("tel:5173237929"));

             startActivity(intent); 
         } 
       });

以下是我在清单中的许可:

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

为什么这不起作用超出了我....我创造了意图,并启动它,然后当我测试它时强制关闭???我觉得你们堆栈上的人可以解决这个问题没有问题=)

编辑:

    [2011-08-27 09:43:00 - HelloListView] ------------------------------
    [2011-08-27 09:43:00 - HelloListView] Android Launch!
    [2011-08-27 09:43:00 - HelloListView] adb is running normally.
    [2011-08-27 09:43:00 - HelloListView] Performing com.hlv.kk.HelloListView activity launch
    [2011-08-27 09:43:04 - HelloListView] WARNING: Application does not specify an API levelrequirement!
    [2011-08-27 09:43:04 - HelloListView] Device API version is 8 (Android 2.2.2)
    [2011-08-27 09:43:05 - HelloListView] Application already deployed. No need to reinstall.
    [2011-08-27 09:43:05 - HelloListView] Starting activity com.hlv.kk.HelloListView on device 04036CA51900D00F
    [2011-08-27 09:43:05 - HelloListView] ActivityManager: Starting: Intent {  act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]          cmp=com.hlv.kk/.HelloListView }

编辑#2:

    09-02 20:25:06.874: INFO/ActivityManager(6146): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
    09-02 20:25:07.030: INFO/ActivityManager(6146): Starting activity: Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster }
    09-02 20:25:07.045: WARN/ActivityManager(6146): Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
    09-02 20:25:07.061: DEBUG/AndroidRuntime(8386): Shutting down VM
    09-02 20:25:07.061: WARN/dalvikvm(8386): threadid=1: thread exiting with uncaught exception (group=0x4001d7e0)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386): FATAL EXCEPTION: main
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386): java.lang.RuntimeException: Unable to start activity ComponentInfo{android/com.android.internal.app.ChooserActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.os.Looper.loop(Looper.java:123)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at java.lang.reflect.Method.invoke(Method.java:521)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at dalvik.system.NativeStart.main(Native Method)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5173237929 flg=0x3000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44a5f890 8386:com.hlv.kk/10051} (pid=8386, uid=10051) requires android.permission.CALL_PHONE
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.os.Parcel.readException(Parcel.java:1247)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.os.Parcel.readException(Parcel.java:1235)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.Activity.startActivityForResult(Activity.java:2817)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.Activity.startActivity(Activity.java:2923)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:95)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:54)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    09-02 20:25:07.100: ERROR/AndroidRuntime(8386):     ... 11 more
    09-02 20:25:07.147: WARN/ActivityManager(6146):   Force finishing activity android/com.android.internal.app.ChooserActivity
    09-02 20:25:07.147: WARN/ActivityManager(6146):   Force finishing activity com.hlv.kk/.HelloListView
    09-02 20:25:07.647: WARN/ActivityManager(6146): Activity pause timeout for HistoryRecord{44ad1490 android/com.android.internal.app.ChooserActivity}
    09-02 20:25:07.819: INFO/ActivityManager(6146): No longer want com.google.android.gallery3d (pid 8199): hidden #16
    09-02 20:25:10.210: INFO/Process(8386): Sending signal. PID: 8386 SIG: 9
    09-02 20:25:10.217: INFO/ActivityManager(6146): Process com.hlv.kk (pid 8386) has died.
    09-02 20:25:10.217: INFO/WindowManager(6146): WIN DEATH: Window{44a05de8 com.hlv.kk/com.hlv.kk.HelloListView paused=false}
    09-02 20:25:10.264: WARN/InputManagerService(6146): Got RemoteException sending setActive(false) notification to pid 8386 uid 10051
    09-02 20:25:12.092: INFO/WindowManager(6146): Setting rotation to 3, animFlags=0
    09-02 20:25:12.116: INFO/ActivityManager(6146): Config changed: { scale=1.0 imsi=310/4 loc=en_US touch=3 keys=2/1/2 nav=2/2 orien=2 layout=34 uiMode=17 seq=45}
    09-02 20:25:12.163: INFO/UsageStats(6146): Unexpected resume of com.android.launcher while already resumed in com.android.launcher
    09-02 20:25:13.186: DEBUG/dalvikvm(6224): GC_EXPLICIT freed 11518 objects / 579136 bytes in 69ms

2 个答案:

答案 0 :(得分:0)

试试这个:

startActivity(Intent.createChooser(intent, "phone"));

而不是startActivity(intent)

修改

只是一个猜测,但请确保您的权限是在应用程序标记之外

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

答案 1 :(得分:0)

我忘了添加权限= /

我的错误lol

但是对于在这个页面上偶然发现的人来说,如果您遇到同样的问题,请确保添加:

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

到结束清单标记

正上方的清单文件中
    </manifest>

在清单文件的末尾

对不起其他人浪费你的时间