我在我发布的应用中使用Android V2 Google地图库(Google Play服务)。我一直看到Google Play中出现的零星异常似乎表明支持地图片段偶尔会尝试检查网络状态。但是,库文档未提及此权限是必需的。我不直接在我的应用程序中检查网络状态,所以我没有声明此权限。因此,在膨胀支持地图片段时,有时会抛出SecurityException
:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foo/com.foo.ui.TransactionDetailActivity}: android.view.InflateException: Binary XML file line #327: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #327: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:459)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(SourceFile:119)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SourceFile:262)
at com.foo.ui.TransactionDetailActivity.onCreate(SourceFile:129)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10106 nor current process has android.permission.ACCESS_NETWORK_STATE.
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:623)
at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:425)
at maps.bm.e.e(Unknown Source)
at maps.bm.e.a(Unknown Source)
at maps.z.ag.a(Unknown Source)
at maps.z.ag.a(Unknown Source)
at maps.z.ag.a(Unknown Source)
at maps.z.bw.a(Unknown Source)
at maps.z.r.onCreateView(Unknown Source)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
at android.os.Binder.transact(Binder.java:310)
at com.google.android.gms.maps.a.l.a(Unknown Source)
at com.google.android.gms.maps.m.a(Unknown Source)
at com.google.android.gms.internal.ap.a(Unknown Source)
at com.google.android.gms.internal.al.a(Unknown Source)
at com.google.android.gms.internal.al.a(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:846)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1061)
at android.support.v4.app.FragmentManagerImpl.addFragment(SourceFile:1160)
at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:272)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
... 28 more
我已在我的清单中声明了相关权限,并会查看是否可以解决问题。然而,有人认为这只会发生在某些设备而不是其他设备上。例如,这在我们的内部测试设备和许多其他设备上运行良好。有没有人对这个神秘的问题有任何见解?它可能是由一个程序错误引起的吗?
编辑1:使用Google Play服务库的2.0.10版(541717-10)时发生此错误。
答案 0 :(得分:1)
使用最新版本的Google Play服务库,documentation has been updated表示需要此权限。
release notes表示需要此权限的原因:
改善了恢复网络连接的速度。此修复程序需要ACCESS_NETWORK_STATE权限。
答案 1 :(得分:0)
是。任何使用getActiveNetworkInfo()
方法都需要网络状态访问权限。
你的Manifest中的以下行应该可以解决问题:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />