0

我正在尝试使用 cordova 2.2 版本获取设备的联系人。当我在模拟器中运行应用程序时,它显示应用程序已意外停止。logcat 显示以下错误。

08-21 19:04:27.999: E/AndroidRuntime(4650): FATAL EXCEPTION: main
08-21 19:04:27.999: E/AndroidRuntime(4650): java.lang.SecurityException:                    
                                     ConnectivityService: Neither user 10035 nor current                                                                                                                                  process has android.permission.ACCESS_NETWORK_STATE.
08-21 19:04:27.999: E/AndroidRuntime(4650): at                                                                                                 android.os.Parcel.readException(Parcel.java:1322)
08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.os.Parcel.readException(Parcel.java:1276)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:345)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:251)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at org.apache.cordova.NetworkManager.execute(NetworkManager.java:127)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
08-21 19:04:27.999: E/AndroidRuntime(4650):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:43)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:213)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.os.Handler.dispatchMessage(Handler.java:99)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.os.Looper.loop(Looper.java:123)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at android.app.ActivityThread.main(ActivityThread.java:3683)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at java.lang.reflect.Method.invokeNative(Native Method)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at java.lang.reflect.Method.invoke(Method.java:507)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

08-21 19:04:27.999: E/AndroidRuntime(4650):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

您是否将所有权限添加到您的 AndroidManifest.xml 文件?根据错误消息,由于某种原因,该应用似乎没有访问权限android.permission.ACCESS_NETWORK_STATE(不确定为什么您需要联系人的该权限。)

2.2 中可用的权限列表是:

<uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.RECEIVE_SMS" />
 <uses-permission android:name="android.permission.RECORD_AUDIO" />
 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
 <uses-permission android:name="android.permission.READ_CONTACTS" />
 <uses-permission android:name="android.permission.WRITE_CONTACTS" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
 <uses-permission android:name="android.permission.BROADCAST_STICKY" />

基于 2.2 联系人的文档: http: //cordova.apache.org/docs/en/2.2.0/cordova_contacts_contacts.md.html#Contacts您需要添加:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
于 2013-08-21T14:21:37.847 回答