AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
package="com.pmss"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.pmss.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.pmss.permission.MAPS_RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
<activity
android:name="com.pmss.SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.pmss.Login"
android:label="@string/app_main" >
<intent-filter android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity
android:name="com.pmss.Register"
android:label="@string/button_register"
android:parentActivityName="com.pmss.Login" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Login" />
</activity>
<activity
android:name="com.pmss.MainMenu"
android:label="@string/title_activity_main_menu"
android:parentActivityName="com.pmss.Login" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Login" />
</activity>
<activity
android:name="com.pmss.UserInfo"
android:label="@string/title_activity_user_info"
android:parentActivityName="com.pmss.MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.MainMenu" />
</activity>
<activity
android:name="com.pmss.Payment"
android:label="@string/title_activity_payment"
android:parentActivityName="com.pmss.MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.MainMenu" />
</activity>
<activity
android:name="com.pmss.TrackParcel"
android:label="@string/title_activity_track_parcel"
android:parentActivityName="com.pmss.MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.MainMenu" />
</activity>
<activity
android:name="com.pmss.TrackMap"
android:label="@string/title_activity_track_map"
android:parentActivityName="com.pmss.Login" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Login" />
</activity>
<activity
android:name="com.pmss.CheckCard"
android:label="@string/title_activity_check_card"
android:parentActivityName="com.pmss.MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.MainMenu" />
</activity>
<activity
android:name="com.pmss.RequestService"
android:label="@string/title_activity_request_service"
android:parentActivityName="com.pmss.MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.MainMenu" />
</activity>
<activity
android:name="com.pmss.StaffMainMenu"
android:label="@string/title_activity_main_menu"
android:parentActivityName="com.pmss.Login" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Login" />
</activity>
<activity
android:name="com.pmss.StaffInfo"
android:label="@string/title_activity_staff_info"
android:parentActivityName="com.pmss.StaffMainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.StaffMainMenu" />
</activity>
<activity
android:name="com.pmss.FulfillRequest"
android:label="@string/title_activity_fulfill_request"
android:parentActivityName="com.pmss.StaffMainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.StaffMainMenu" />
</activity>
<activity
android:name="com.pmss.OnlinePayment"
android:label="@string/title_activity_online_payment"
android:parentActivityName="com.pmss.Payment" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Payment" />
</activity>
<activity
android:name="com.pmss.CardPayment"
android:label="@string/title_activity_card_payment"
android:parentActivityName="com.pmss.Payment" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Payment" />
</activity>
<activity
android:name="com.pmss.CashPayment"
android:label="@string/title_activity_cash_payment"
android:parentActivityName="com.pmss.Payment" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.Payment" />
</activity>
<activity
android:name="com.pmss.StaffTrackParcel"
android:label="@string/title_activity_staff_track_parcel"
android:parentActivityName="com.pmss.StaffMainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pmss.StaffMainMenu" />
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
这是activity_track_map.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
这是TrackMap.class
public class TrackMap extends FragmentActivity{
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_track_map);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
这是logcat
05-08 01:07:36.429: E/AndroidRuntime(18559): FATAL EXCEPTION: main
05-08 01:07:36.429: E/AndroidRuntime(18559): Process: com.pmss, PID: 18559
05-08 01:07:36.429: E/AndroidRuntime(18559): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pmss/com.pmss.TrackMap}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.os.Handler.dispatchMessage(Handler.java:102)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.os.Looper.loop(Looper.java:136)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-08 01:07:36.429: E/AndroidRuntime(18559): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 01:07:36.429: E/AndroidRuntime(18559): at java.lang.reflect.Method.invoke(Method.java:515)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-08 01:07:36.429: E/AndroidRuntime(18559): at dalvik.system.NativeStart.main(Native Method)
05-08 01:07:36.429: E/AndroidRuntime(18559): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.Activity.setContentView(Activity.java:1929)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.pmss.TrackMap.onCreate(TrackMap.java:14)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.Activity.performCreate(Activity.java:5231)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-08 01:07:36.429: E/AndroidRuntime(18559): ... 11 more
05-08 01:07:36.429: E/AndroidRuntime(18559): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 1. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.internal.q.B(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.internal.q.A(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.dynamic.a.a(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
05-08 01:07:36.429: E/AndroidRuntime(18559): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-08 01:07:36.429: E/AndroidRuntime(18559): ... 21 more
我在新项目上尝试了这个编码,它可以显示地图,但是这个编码不会显示地图,因为它似乎强制关闭我的应用程序。它一直说我没有
的元数据 <meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
我把它放在我的AndroidManifest.xml中,它只是说它无法找到我的元数据标签。感谢所有的帮助,我将非常感谢。
答案 0 :(得分:0)
将@integer/google_play_services_version
替换为4323000
看到这个
google-play-services_lib - &gt; res - &gt;值 - &gt; version.xml
了解Google Play服务的正确版本
答案 1 :(得分:0)
项目 - &gt; res - &gt;值 - &gt; intergers.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="google_play_services_version">1</integer>
</resources>
此处指定的值为1.这与我的google play服务版本4323000不匹配。我所做的是将值从1更改为4323000.它运行良好。
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
我没有在这个元数据标记中的android:值中进行硬编码。