PhoneGap / Cordova应用程序与Google Analytics插件仅在Android上出现错误

时间:2014-01-06 11:38:01

标签: android eclipse cordova google-analytics phonegap-plugins

我正在使用PhoneGap版本3.3.0-0.18.0

我正在使用这个插件:

https://github.com/phonegap-build/GAPlugin

它适用于iOS,但在Android上我似乎无法记录任何事件,我在Android设备上运行时会在Eclipse中出现以下内容:

01-06 11:36:23.705: E/GAV2(3478): Thread[GAThread,5,main]: Error on GAThread: java.lang.SecurityException: ConnectivityService: Neither user 10132 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-06 11:36:23.705: E/GAV2(3478):   at android.os.Parcel.readException(Parcel.java:1425)
01-06 11:36:23.705: E/GAV2(3478):   at android.os.Parcel.readException(Parcel.java:1379)
01-06 11:36:23.705: E/GAV2(3478):   at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:667)
01-06 11:36:23.705: E/GAV2(3478):   at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:458)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.SimpleNetworkDispatcher.okToDispatch(SimpleNetworkDispatcher.java:69)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.PersistentAnalyticsStore.dispatch(PersistentAnalyticsStore.java:483)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.GAServiceProxy.dispatchToStore(GAServiceProxy.java:245)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.GAServiceProxy.sendQueue(GAServiceProxy.java:216)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.GAServiceProxy.access$000(GAServiceProxy.java:27)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.GAServiceProxy$2.run(GAServiceProxy.java:198)
01-06 11:36:23.705: E/GAV2(3478):   at com.google.analytics.tracking.android.GAThread.run(GAThread.java:520)
01-06 11:36:23.705: E/GAV2(3478): Thread[GAThread,5,main]: Google Analytics is shutting down.

从阅读错误消息看,似乎应用程序没有发送GA数据的权限,是否有办法解决这个问题?

1 个答案:

答案 0 :(得分:2)

在您的清单中添加以下权限:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

需要此权限才能添加到每个phonegap项目中。因为我们的html文件将在浏览器&amp;我们的一些样式表&amp; js需要检查网络的当前状态。所以它可以检测到是否有任何可用的网络连接&amp;然后就可以继续了。要检查状态,android具有权限<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />