Reputation: 1909
I tried to use a Google+ login in my app.
While writing code, I am getting this problem:
The method getIntentSender() is undefined for the type ConnectionResult
I added permissions for Internet, getaccounts, and usecredentials. I added the Google+ services library.
The code is here:
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
}
}
I have updated the code, but at run time I am getting a Nullpointer Exception...
Upvotes: 0
Views: 879
Reputation: 2288
Use:
result.getResolution().getIntentSender()
I had this problem and solved it that way.
Upvotes: 9
Reputation: 1909
I got the solution on Stack Overflow.
I can get the application working using the below commands instead of .addApi(Plus.API, null)
.
addApi(Plus.API)
addApi(Plus.API, PlusOptions.builder().build())
But what is the difference between these two?
Upvotes: 0
Reputation: 1891
result.getStatus().hasResolution()
or
if ( ( result.getStatus().getIntentSender() ) != null ) { ......... ......... }
Hope it helps.
Upvotes: 0