我刚刚在应用程序中实现了地图,它可以在Galaxy S3中完美运行。使用带有API8的旧手机HTC Sense测试我的应用程序,该应用程序会出现充气机问题。我认为这可能与OS或OGL2有关。 isGooglePlayServicesAvailable(this)返回正确的值。请在这里帮助我:
Activity.java
public class MyActivity extends Activity
{
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.initializeInterface();
}
private void initializeInterface() {
final int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
this.setContentView(R.layout.main);
}
}
main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
class="com.google.android.gms.maps.MapFragment"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header" />
manifest.xml
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.stuff.permission.MAPS_RECEIVE" />
<permission
android:name="com.stuff.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="@drawable/icon"
android:label="@string/application_name" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/map_api_key_device"/>
<activity
android:name=".MyActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
错误
12-13 12:14:13.865: E/My ERROR(22878): Binary XML file line #85: Error inflating class fragment
12-13 12:14:13.875: E/android.view.LayoutInflater.createViewFromTag(22878): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
12-13 12:14:13.895: E/android.view.LayoutInflater.rInflate(22878): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-13 12:14:13.935: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-13 12:14:13.945: E/com.android.internal.policy.impl.PhoneWindow.setContentView(22878): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
12-13 12:14:13.945: E/android.app.Activity.setContentView(22878): at android.app.Activity.setContentView(Activity.java:1654)
最佳答案
这与您试图在API级别8设备上使用本机API级别11片段有关。如果希望代码在Android 3.0之前的版本上运行,请切换到FragmentActivity
和SupportMapFragment
。