当我在android studio中运行我的模拟器时,我遇到了问题。模拟器提示我"除非您更新Google Play服务" ,否则Google Map API演示将无法运行。
我看到了以下错误消息:
--------- beginning of crash 02-03 13:29:47.762 2870-2870/com.example.xxx_000.googlemapapidemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.xxx_000.googlemapapidemo, PID: 2870
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.gms&pcampaignid=gcore_9683000--- flg=0x80000 pkg=com.android.vending }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.google.android.gms.dynamic.zza$5.onClick(Unknown Source)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 02-03 13:29:49.877 2870-2870/com.example.xxx_000.googlemapapidemo I/Process: Sending signal. PID: 2870 SIG: 9 02-03 13:35:13.441 5142-5142/com.example.xxx_000.googlemapapidemo W/System: ClassLoader referenced unknown path: /data/app/com.example.xxx_000.googlemapapidemo-1/lib/x86 02-03 13:35:13.504 5142-5142/com.example.xxx_000.googlemapapidemo I/FirebaseInitProvider: FirebaseApp initialization unsuccessful 02-03 13:35:13.713 5142-5142/com.example.xxx_000.googlemapapidemo W/GooglePlayServicesUtil: Google Play services out of date. Requires 9683000 but found 9452470 02-03 13:35:13.726 5142-5142/com.example.xxx_000.googlemapapidemo ... 5142-5261/com.example.xxx_000.googlemapapidemo D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
我的build.gradle文件是这样的:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.xxx_000.googlemapapidemo"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
任何人都可以帮助我吗?谢谢!
答案 0 :(得分:0)
更新您的模拟器并创建一个API级别为(with Google APIs)
或使用真实设备的模拟器。
答案 1 :(得分:0)
虽然接受的答案适用于模拟器,但这可能是真实设备上的真正问题,并且此解决方案不适用于真实设备。这可能发生在具有过时版本的Google Play服务的旧设备上。
为解决此问题,Google Play服务库提供了一组API来检查Google Play服务的可用性,主要是GoogleApiAvailability
类提供了一些方法来处理可用性问题,例如过时的版本。< / p>
现在,要检测设备是否提供Google Play服务,我通常会创建一个辅助方法来运行检查
private boolean checkPlayServices(){
GoogleApiAvailability gaa = GoogleApiAvailability.getInstance();
int result = gaa.isGooglePlayServicesAvailable(getApplicationContext());
if(result != ConnectionResult.SUCCESS){
if(gaa.isUserResolvableError(result)){
gaa.getErrorDialog(this,result, REQUEST_PLAY_SERVICES_RESOLUTION).show();
}
return false;
}
return true;
}
此辅助方法通过检查从isGooglePlayServicesAvailable
返回的错误代码来检查Google Play服务是否可用。然后,它会调用isUserResolvableError
来确定错误是否可由用户解析(例如,通过更新Google Play服务)。如果它是可解析的,则会显示一个对话框,供用户确认他希望系统解决错误。然后在Activity的onCreate
方法中调用它,我按以下方式运行该检查
//I normally assume Google Play services is available
private boolean playServicesAvailable = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_selector);
//check for rare case where Google Play Services is not available
playServicesAvailable = checkPlayServices();
if(!playServicesAvailable){
//hide UI elements and turn off features that rely on Google Play Services
}
}
希望它有所帮助