我遵循将Google+集成到Android应用程序中
但是当我返回给我时,我有问题Bundle always null
。
我不知道如何get all information related to my Google+ account
如果Bundle返回null。
所以how Bundle is not return null
。
请帮帮我,
谢谢,
UPDATE我只知道如何通过使用以下代码获取与我的帐户相关的信息:
@Override
public void onConnected() {
...
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String personGooglePlusProfile = currentPerson.getUrl();
}
}
无论如何,我不知道Bundle was returned
做什么事?
p/s:这是代码:
Java code
:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_create_account);
/**
* Initial Google Plus authentication
*/
mGap = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();
}
@Override
public void onConnected(Bundle bundle) {
// TODO BUNDLE ALWAYS RETURN NULL
Log.i("", "onConnected " + bundle);
if (bundle != null)
Log.i("", "bundle " + bundle.size() + " " + bundle.toString());
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i("", "onConnectionFailed ");
if (!mIntentInProgress && connectionResult.hasResolution()) {
try {
mIntentInProgress = true;
startIntentSenderForResult(connectionResult.getResolution().getIntentSender(),
0, null, 0, 0, 0);
} catch (IntentSender.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;
mGap.connect();
}
}
}
@Override
public void onConnectionSuspended(int i) {
Log.i("", "onConnectionSuspended " + i);
}
Manifest.xml file
:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
build.grade
file:
compile 'com.google.android.gms:play-services:5.0.89'
这个文档说"注意,connectionHint Bundle的内容是由特定的服务定义的…如果该服务没有提供任何内容,则可能为空"。我个人不使用这个包。
一旦你连接上了,你就可以获得其他信息(比如用户圈子里的人)。
希望您实现ResultCallback<People.LoadPeopleResult>
接口。
在OnResult()方法中,我像这样检索用户详细信息,如下所示。
public class HomeActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,ResultCallback<People.LoadPeopleResult> {
...
@Override
public void onResult(People.LoadPeopleResult loadPeopleResult) {
getDisplayName(loadPeopleResult);
getProfileInformation();
}
...
private void getProfileInformation() {
Log.d(TAG,"getProfileInformation method called from onResult");
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
Person.Image personPhoto = currentPerson.getImage();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
String personGooglePlusProfile = currentPerson.getUrl();
Log.d(TAG,"Google Plus user Details :"+"nPerson Name :"+personName+"nEmail :"+email+"npersonGooglePlusProfile:"+personGooglePlusProfile);
}
}
我仍然得到空束,即使我再次尝试在OnActivityForResult方法连接
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
Log.d(TAG,"Google onActivityResult called");
if (requestCode == GOOGLE_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
我遵循谷歌开发人员链接