二进制XML文件行#:错误充气类片段:只有在Android(6.0)-Marshmallow [英] Binary XML file line #: Error inflating class fragment : Only on Android (6.0)-Marshmallow
问题描述
我不能够证明在Android M.
在谷歌地图
下面是布局的xml:
块引用><?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
的xmlns:车轮=http://schemas.android.com/apk/res-auto
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent><包括
布局=@布局/ toolbar_layout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT/><的LinearLayout
机器人:方向=垂直
机器人:ID =@ + ID / content_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <片段
类=com.google.android.gms.maps.SupportMapFragment
机器人:ID =@ + ID / GoogleMap的
机器人:layout_weight =1
机器人:layout_width =match_parent
机器人:layout_height =0dp
机器人:layout_gravity =中心 />
< / LinearLayout中> < / LinearLayout中>
AndroidManifest文件:
块引用><许可
机器人:名字=com.xxx.yyy.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.xxx.yyy.permission.MAPS_RECEIVE/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
和内部应用程序标记:
块引用><元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=@字符串/ MAPS_API_KEY/> &所述;元数据
机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>我在运行时请求权限:
如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.M&放大器;&安培;!(checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)= PackageManager.PERMISSION_GRANTED | | checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)= PackageManager.PERMISSION_GRANTED))!
{
requestPermissions(新的String [] {Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION);
}这是回调:
@覆盖
公共无效onRequestPermissionsResult(INT申请code,字符串权限[],INT [] grantResults){
开关(要求code){
案例PERMISSION_REQUEST_COARSE_LOCATION:{
如果(grantResults [0] == PackageManager.PERMISSION_GRANTED&放大器;&放大器; grantResults [1] == PackageManager.PERMISSION_GRANTED){
//访问位置
}其他{
Utils.showToast(getApplicationContext(),直到你授予的权限,就无法访问定位服务);
} }
打破;
}
}我得到这个例外
android.view.InflateException:二进制XML文件行#:错误充气类片段。仅适用于Android 6
这是显示地图,而在Android的版本,其余的任何问题。请帮帮我。
解决方案你有Android的-M设备上的SD卡?如果没有,请插入SD卡,然后再试一次。
I'm not able to show the google map on Android M.
Here is layout xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:wheel="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"/> <LinearLayout android:orientation="vertical" android:id="@+id/content_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.google.android.gms.maps.SupportMapFragment" android:id="@+id/googleMap" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" /> </LinearLayout> </LinearLayout>
AndroidManifest File:
<permission android:name="com.xxx.yyy.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.xxx.yyy.permission.MAPS_RECEIVE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
And inside application tag:
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/maps_api_key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
I'm requesting for permissions at runtime:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION); }
And this is the callback:
@Override public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSION_REQUEST_COARSE_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { //Access Location } else { Utils.showToast(getApplicationContext(), "Until you grant the permissions, You cannot Access Location Service"); } } break; } }
I'm getting this exception
"android.view.InflateException: Binary XML file line #: Error inflating class fragment" only on Android 6.
It is showing map without any issue on rest of the versions of android. Please help me.
解决方案Do you have SD card on Android-M device? If no, insert SD card and try again.
这篇关于二进制XML文件行#:错误充气类片段:只有在Android(6.0)-Marshmallow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!