Проверьте правильность службы Google Play: "К сожалению приложение перестало работать"
Приложение Сбой при каждом запуске на моем телефоне. Здесь что-то не так? Он говорит, что "appname" перестало работать. Я также пробовал другие подходы к проверке сервисов googleplay, но он всегда сбой. Я обновил свои сервисы google play и хорошо работаю над google map v2. Любые решения для этого кода? Он сбой на моем телефоне под управлением Android 4.1.2 и на моем AVD.
package com.example.checkgoogleplayproject;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
// Getting reference to TextView to show the status
TextView tvStatus = (TextView)findViewById(R.id.tv_status);
// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status==ConnectionResult.SUCCESS)
tvStatus.setText("Google Play Services are available");
else{
tvStatus.setText("Google Play Services are not available");
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Ответы
Ответ 1
Спасибо, ребята, за ваши ответы. Я только что понял это из своего LogCat.
Я должен был включить это в свой манифест Android.
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
Ответ 2
Чтобы проверить, доступен ли GooglePlayServices
или нет, используйте GoogleApiAvailability
. isGooglePlayServicesAvailable()
, Как GooglePlayServicesUtil
. isGooglePlayServicesAvailable()
устаревший.
public boolean isGooglePlayServicesAvailable(Context context){
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
return resultCode == ConnectionResult.SUCCESS;
}
Обновление:. Проверьте, доступна ли служба просмотра google. Если служба Google Play недоступна и исправлена ошибка, откройте диалоговое окно для устранения ошибки.
public boolean isGooglePlayServicesAvailable(Activity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if(status != ConnectionResult.SUCCESS) {
if(googleApiAvailability.isUserResolvableError(status)) {
googleApiAvailability.getErrorDialog(activity, status, 2404).show();
}
return false;
}
return true;
}
Ответ 3
Я не знаю, где разместить это, но трудность в правильном рабочем процессе проверки игровых сервисов google - это ум, я использую некоторые пользовательские классы, но вы можете получить точку...
protected boolean checkPlayServices() {
final int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity());
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity(),
PLAY_SERVICES_RESOLUTION_REQUEST);
if (dialog != null) {
dialog.show();
dialog.setOnDismissListener(new OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
if (ConnectionResult.SERVICE_INVALID == resultCode) activity().finish();
}
});
return false;
}
}
new CSAlertDialog(this).show("Google Play Services Error",
"This device is not supported for required Goole Play Services", "OK", new Call() {
public void onCall(Object value) {
activity().finish();
}
});
return false;
}
return true;
}
Ответ 4
Измените
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
к
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext();
Ответ 5
Вы установите change checkPlayServices в read doc в новом 2016 введите описание ссылки здесь
![введите описание изображения здесь]()
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
Ответ 6
Добавьте этот метод в свой экран заставки; Ваше приложение не будет запускаться вообще, если у вас нет обновленных или установленных сервисов Google Play.
Dialog errorDialog;
private boolean checkPlayServices() {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (googleApiAvailability.isUserResolvableError(resultCode)) {
if (errorDialog == null) {
errorDialog = googleApiAvailability.getErrorDialog(this, resultCode, 2404);
errorDialog.setCancelable(false);
}
if (!errorDialog.isShowing())
errorDialog.show();
}
}
return resultCode == ConnectionResult.SUCCESS;
}
и называть его только при возобновлении
@Override
protected void onResume() {
super.onResume();
if (checkPlayServices()) {
startApp();
}
}
Ответ 7
Вы можете проверить наличие Службы Службы как это:
/**
* Check if correct Play Services version is available on the device.
*
* @param context
* @param versionCode
* @return boolean
*/
public static boolean checkGooglePlayServiceAvailability(Context context, int versionCode) {
// Query for the status of Google Play services on the device
int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if ((statusCode == ConnectionResult.SUCCESS)
&& (GooglePlayServicesUtil.GOOGLE_PLAY_SERVICES_VERSION_CODE >= versionCode)) {
return true;
} else {
return false;
}
}
И вы можете просто передать -1
для параметра versionCode
.