我无法在Android M上显示谷歌地图。
这是布局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文件:
<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"/>
内部应用程序标记:
<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" />
我在运行时请求权限:
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);
}
这就是回调:
@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;
}
}
我收到此异常
"android.view.InflateException: Binary XML file line #: Error inflating class fragment" only on Android 6.
在其余的android版本上显示地图没有任何问题。请帮我。
答案 0 :(得分:1)
我在xml中找不到任何奇怪的东西。但是,通胀错误可能不会仅在此布局上发生。例如,此布局xml包含toolbar_layout,可能错误在toolbar_layout.xml中。
我建议你,也许你可以标出一些标签,然后再试一次,找出查找标签导致这个例外。
答案 1 :(得分:1)
Android-M设备上有SD卡吗?如果不是,请插入SD卡并重试。