我正在使用 Eclipse helios 和 Android 4.1.2 我已遵循以下文档https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw并完全按照教程中的描述完成编码。当我运行我在模拟器上的应用程序显示“除非您更新 google play 服务,否则此应用程序将无法运行”,但在具有 google play 服务更新版本的真实设备上,它会出现“应用程序已停止工作”。任何帮助表示赞赏。
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emeterfinalapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<permission
android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name="com.example.emeterfinalapp.EmeterMainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.emeterfinalapp.EnterLocationActivity"
android:label="@string/title_activity_enter_location"
android:parentActivityName="com.example.emeterfinalapp.EmeterMainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.emeterfinalapp.EmeterMainActivity" />
</activity>
<activity
android:name="com.example.emeterfinalapp.SelectLocation"
android:label="@string/title_activity_select_location"
android:parentActivityName="com.example.emeterfinalapp.EnterMainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.emeterfinalapp.EnterMainActivity" />
</activity>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key"/>
</manifest>
这是我的 main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SelectLocation" >
<Button
android:id="@+id/satellite_button"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/mapview_button"
android:text="@string/satellitebuttontext" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/satellite_button"/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/mapview_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/mapbuttontext" />
</RelativeLayout>
这是我的活动
package com.example.emeterfinalapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class SelectLocation extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_location);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
我为我的项目提供了 google_play_services lib 的引用,在我的 lib 中添加了 google_play_service 和 android.support.v4 jar 文件....如果我仍然缺少任何东西,请指导....
我有 api 密钥,我在 maifest 中添加了它现在编辑的上方...
amd 这是我手机日志中的错误跟踪
I/ActivityManager( 282): Displayed com.example.emeterfinalapp/.EmeterMainActivity: +206ms
I/ActivityManager( 282): Displayed com.example.emeterfinalapp/.EnterLocationActivity: +224ms
W/InputDispatcher( 282): channel '2c3dbfd0 com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
E/InputDispatcher( 282): channel '2c3dbfd0 com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
W/InputDispatcher( 282): Attempted to unregister already unregistered input channel '2c3dbfd0 com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)'
W/InputDispatcher( 282): channel '2c504fb8 com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
E/InputDispatcher( 282): channel '2c504fb8 com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
W/InputDispatcher( 282): Attempted to unregister already unregistered input channel '2c504fb8 com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)'