Это мой первый опыт использования Google Play Services.Не удается инициализировать службы Google Play
Я добавил библиотеки «google-play-services-lib» и «BaseGameUtils». Я изменил свой класс расширяет "BaseGameActivity"
Вот код:
public class MainActivity extends BaseGameActivity implements View.OnClickListener {
Button skipBut;
View signInBut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
skipBut = (Button) findViewById(R.id.justPlay);
signInBut = (View) findViewById(R.id.sign_in_button);
skipBut.setOnClickListener(this);
signInBut.setOnClickListener(this);
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
if(view.getId() == R.id.sign_in_button){
beginUserInitiatedSignIn();
}
else if(view.getId() == R.id.justPlay){
// play without sign in .... code ....
}
}
@Override
public void onSignInFailed() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
}
@Override
public void onSignInSucceeded() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
}
}
Но мой приложения рушится вниз. Я не могу найти почему. Примечание: Я также добавил идентификатор приложения в манифест и в строки (как app_id).
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.games.*****id****"
android:value="@string/app_id" />
Вот LogCat:
09-08 14:57:19.500: W/ActivityThread(18213): Application com.cdev.colormatch is waiting for the debugger on port 8100...
09-08 14:57:19.520: I/System.out(18213): Sending WAIT chunk
09-08 14:57:19.540: I/dalvikvm(18213): Debugger is active
09-08 14:57:19.720: I/System.out(18213): Debugger has connected
09-08 14:57:19.725: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:19.925: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.125: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.325: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.525: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.725: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:20.925: I/System.out(18213): waiting for debugger to settle...
09-08 14:57:21.125: I/System.out(18213): debugger has settled (1465)
09-08 14:57:21.505: W/PopupManager(18213): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
09-08 14:57:22.225: D/dalvikvm(18213): threadid=1: still suspended after undo (sc=1 dc=1)
Update
Я попытался с помощью игры помощника без расширения до GameBaseActivity (как описано в https://developers.google.com/games/services/android/init#using_gamehelper_without_basegameactivity)
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
Button skipBut;
View signInBut;
GameHelper mHelper;
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false;
GoogleApiClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
skipBut = (Button) findViewById(R.id.justPlay);
signInBut = (View) findViewById(R.id.sign_in_button);
skipBut.setOnClickListener(this);
signInBut.setOnClickListener(this);
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this);
builder.addApi(Games.API)
.addApi(Plus.API)
.addApi(AppStateManager.API)
.addScope(Games.SCOPE_GAMES)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(AppStateManager.SCOPE_APP_STATE);
mClient = builder.build();
mHelper = new GameHelper(this, GameHelper.CLIENT_ALL);
GameHelperListener listener = new GameHelper.GameHelperListener() {
@Override
public void onSignInSucceeded() {
// handle sign-in succeess
}
@Override
public void onSignInFailed() {
// handle sign-in failure (e.g. show Sign In button)
}
};
mHelper.setup(listener);
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
if(view.getId() == R.id.sign_in_button){
mHelper.beginUserInitiatedSignIn();
}
else if(view.getId() == R.id.justPlay){
// skipp sign in
}
}
}
Но все еще падает: (
Это может быть полезен: https://github.com/marmalade/s3eGooglePlayGames/blob/master/source/android/GameHelper.java – 2Dee
Это класс GameHelper, который я использую в качестве библиотеки. Что вы пытаетесь мне указать? @ 2Dee – ctarimli
Указанный логарифм не содержит ошибок, поэтому немного сложно определить, в чем проблема. Обновите логарифм с копией, которая включает в себя ошибку (т. Е. Когда приложение выйдет из строя) - с префиксом «E». – free3dom