我正在尝试使用Google+播放服务登录我的应用。代码没有任何错误,它会在模拟器中启动。但是当我点击“使用google登录”按钮时,我在logcat中收到此错误
我不确定为什么会发生这种情况。这是我的MainActivity
课程:
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.util.Log;
import android.view.*;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.common.*;
import com.google.android.gms.common.GooglePlayServicesClient.*;
import com.google.android.gms.plus.PlusClient;
public class MainActivity extends Activity implements View.OnClickListener,
ConnectionCallbacks, OnConnectionFailedListener{
private static final String TAG = "MainActivity";
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private Button signInButton;
private ProgressDialog mConnectionProgressDialog;
private static PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlusClient = new PlusClient.Builder(this, this, this)
.setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/ BuyActivity")
.setScopes("PLUS_LOGIN") // Space separated list of scopes
.build();
// Progress bar to be displayed if the connection failure is not resolved.
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
signInButton =(Button) findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(this);
}
public static PlusClient getPlusClientObject() {
return mPlusClient;
}
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@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);
//signInButton =(Button) findViewById(R.id.sign_in_button);
//signInButton.setOnClickListener(this);
return true;
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the result and resolve the connection failure upon a user click.
mConnectionResult = result;
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
@Override
public void onConnected(Bundle connectionHint) { //this is called when the user has successfully signed in
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
Intent logoutIntention = new Intent(this, LogoutActivity.class);
startActivity(logoutIntention);
}
@Override
public void onDisconnected() {
Log.d(TAG, "disconnected");
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button && !mPlusClient.isConnected()) {
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
mConnectionResult = null;
mPlusClient.connect();
}
}
}
}
}
和我的应用引用google-play-services_lib
具有以下结构:
我不确定为什么会发生这种情况。任何人都可以帮忙吗?
以下是我的模拟器的定义: