Nir*_*jan 0 android google-plus
在编写代码时,我遇到了这个问题:
对于ConnectionResult类型,未定义getIntentSender()方法
我添加了Internet,getaccounts和usecredentials的权限.我添加了Google+服务库.
代码在这里:
package com.niranjan.googleplus;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
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 MainActivity extends ActionBarActivity implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient googleapi;
private static final int RC_SIGN_IN = 0;
private boolean mIntentInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
googleapi = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
protected void onStart(){
super.onStart();
googleapi.connect();
}
protected void onStop(){
super.onStop();
if(googleapi.isConnected()){
googleapi.disconnect();
}
}
@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;
googleapi.connect();
}
}
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!googleapi.isConnecting()) {
googleapi.connect();
}
}
}
public void onConnectionSuspended(int cause) {
googleapi.connect();
}
@Override
public void onConnected(Bundle arg0) {
setContentView(R.layout.activity_main);
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
我已更新代码,但在运行时我得到一个Nullpointer异常...
使用:
result.getResolution().getIntentSender()
Run Code Online (Sandbox Code Playgroud)
我有这个问题并以这种方式解决了.
| 归档时间: |
|
| 查看次数: |
828 次 |
| 最近记录: |