在android中实现google play服务
我将继续学习教程,并且在在android中实现google play服务,android,google-play-services,Android,Google Play Services,我将继续学习教程,并且在onConnectionFailed类中未定义类型ConnectionResult的getIntentSender()方法 完整代码 package com.alfalfa.thisthat; import android.app.Activity; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.os.Bundl
onConnectionFailed
类中未定义类型ConnectionResult的getIntentSender()方法
完整代码
package com.alfalfa.thisthat;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.plus.Plus;
public class LoginActivity extends Activity implements
ConnectionCallbacks, OnConnectionFailedListener {
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 0;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
/* A flag indicating that a PendingIntent is in progress and prevents
* us from starting further intents.
*/
private boolean mIntentInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.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);
return true;
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
startIntentSenderForResult(result.getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnected(Bundle connectionHint) {
// We've resolved any connection errors. mGoogleApiClient can be used to
// access Google APIs on behalf of the user.
}
@Override
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
}
编辑:
LogCat
从今天起,Google Play SDK版本15已被替换为
result.startResolutionForResult(this, // your activity
RC_SIGN_IN);
根据更新的。希望对您有所帮助
result.getResolution().getIntentSender()
如果我将该行更改为上面的行,LoginActivity类不会显示任何错误,但是如果我运行程序的目的是从MainActivity到LoginActivity,则应用程序强制关闭。还有什么我做得不对的吗?谢谢。如果是强制关闭,请发布日志。该错误看起来好像您没有在清单中声明您的活动之一,并且与Google Play服务无关。谢谢,这消除了错误。我说“发生了一个内部错误”,屏幕在闪烁。不知道那是什么。但我想我会把它留给另一个问题。谢谢你的帮助。嗨,这很可能解决问题。。。但是,如果你能提供一些关于它如何工作以及为什么工作的解释,那就太好了:)别忘了——堆栈溢出上有很多新手,他们可以从你的专业知识中学到一两件事——对你来说显而易见的事对他们来说可能不是这样。
result.getResolution().getIntentSender()