在android中的google plus中加载特定可见人
我已经成功地实现了google plus 列出人员活动在android中的google plus中加载特定可见人,android,google-plus,Android,Google Plus,我已经成功地实现了google plus 列出人员活动 public class ListPeopleActivity extends Activity implements PlusClient.ConnectionCallbacks, PlusClient.OnPeopleLoadedListener, PlusClient.OnConnectionFailedListener, DialogInterface.OnCancelListener { private stat
public class ListPeopleActivity extends Activity implements
PlusClient.ConnectionCallbacks, PlusClient.OnPeopleLoadedListener,
PlusClient.OnConnectionFailedListener, DialogInterface.OnCancelListener {
private static final String TAG = "ListPeopleActivity";
private static final String STATE_RESOLVING_ERROR = "resolving_error";
private static final int DIALOG_GET_GOOGLE_PLAY_SERVICES = 1;
private static final int REQUEST_CODE_SIGN_IN = 1;
private static final int REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES = 2;
private ArrayAdapter mListAdapter;
private ListView mPersonListView;
private ArrayList<String> mListItems;
private PlusClient mPlusClient;
private boolean mResolvingError;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.person_list_activity);
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities(MomentUtil.VISIBLE_ACTIVITIES).build();
mListItems = new ArrayList<String>();
mListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mListItems);
mPersonListView = (ListView) findViewById(R.id.person_list);
mResolvingError = savedInstanceState != null
&& savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
int available = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (available != ConnectionResult.SUCCESS) {
showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES);
}
}
@Override
protected Dialog onCreateDialog(int id) {
if (id != DIALOG_GET_GOOGLE_PLAY_SERVICES) {
return super.onCreateDialog(id);
}
int available = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (available == ConnectionResult.SUCCESS) {
return null;
}
if (GooglePlayServicesUtil.isUserRecoverableError(available)) {
return GooglePlayServicesUtil.getErrorDialog(available, this,
REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES, this);
}
return new AlertDialog.Builder(this)
.setMessage(R.string.plus_generic_error).setCancelable(true)
.setOnCancelListener(this).create();
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, mResolvingError);
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@Override
public void onPeopleLoaded(ConnectionResult status,
PersonBuffer personBuffer, String nextPageToken) {
switch (status.getErrorCode()) {
case ConnectionResult.SUCCESS:
mListItems.clear();
try {
int count = personBuffer.getCount();
Log.e("", "count : " + count);
for (int i = 0; i < count; i++) {
mListItems.add(personBuffer.get(i).getDisplayName());
Log.e("", "" + personBuffer.get(i).getDisplayName() + " "
+ personBuffer.get(i).getId() + " isPlusUser : "
+ personBuffer.get(i).isPlusUser()
+ " isVerified : "
+ personBuffer.get(i).isVerified()
+ " hasCircledByCount : "
+ personBuffer.get(i).hasCircledByCount()
+ " getObjectType : "
+ personBuffer.get(i).getObjectType());
}
} finally {
personBuffer.close();
}
mListAdapter.notifyDataSetChanged();
break;
case ConnectionResult.SIGN_IN_REQUIRED:
mPlusClient.disconnect();
mPlusClient.connect();
break;
default:
Log.e(TAG, "Error when listing people: " + status);
break;
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_SIGN_IN:
mResolvingError = false;
handleResult(resultCode);
break;
case REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES:
handleResult(resultCode);
break;
}
}
private void handleResult(int resultCode) {
if (resultCode == RESULT_OK) {
// onActivityResult is called after onStart (but onStart is not
// guaranteed to be called while signing in), so we should make
// sure we're not already connecting before we call connect again.
if (!mPlusClient.isConnecting() && !mPlusClient.isConnected()) {
mPlusClient.connect();
}
} else {
Log.e(TAG, "Unable to sign the user in.");
finish();
}
}
@Override
public void onConnected(Bundle connectionHint) {
mPersonListView.setAdapter(mListAdapter);
// mPlusClient.loadVisiblePeople(this, null);
mPlusClient.loadPeople(this, "103193341800315457743");
}
@Override
public void onDisconnected() {
mPersonListView.setAdapter(null);
mPlusClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
return;
}
mPersonListView.setAdapter(null);
try {
result.startResolutionForResult(this, REQUEST_CODE_SIGN_IN);
mResolvingError = true;
} catch (IntentSender.SendIntentException e) {
// Get another pending intent to run.
mPlusClient.connect();
}
}
@Override
public void onCancel(DialogInterface dialogInterface) {
Log.e(TAG, "Unable to sign the user in.");
finish();
}
公共类ListPeopleActivity扩展活动实现
PlusClient.ConnectionCallbacks、PlusClient.OnPeopleLoadedListener、,
PlusClient.OnConnectionFailedListener,DialogInterface.OnCancelListener{
私有静态最终字符串TAG=“ListPeopleActivity”;
私有静态最终字符串状态\u RESOLVING\u ERROR=“RESOLVING\u ERROR”;
私有静态最终整数对话框\u GET\u GOOGLE\u PLAY\u SERVICES=1;
私有静态最终整数请求\代码\符号\输入=1;
私有静态最终整数请求\代码\获取\谷歌\播放\服务=2;
专用阵列适配器mListAdapter;
私有列表视图mPersonListView;
私人阵列列表;
私有多客户端mPlusClient;
私有布尔mResolvingError;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.person\u list\u活动);
mpluclient=new PlusClient.Builder(this,this,this)
.setVisibleActivities(MomentUtil.VISIBLE_ACTIVITIES).build();
mListItems=新的ArrayList();
mListAdapter=新阵列适配器(此,
android.R.layout.simple_list_item_1,mListItems);
mPersonListView=(ListView)findViewById(R.id.person\u列表);
mResolvingError=savedInstanceState!=null
&&getBoolean(STATE\u RESOLVING\u ERROR,false);
int available=GooglePlayServicesUtil
.isGooglePlayServicesAvailable(此);
如果(可用!=ConnectionResult.SUCCESS){
showDialog(DIALOG\u GET\u GOOGLE\u PLAY\u服务);
}
}
@凌驾
受保护的对话框onCreateDialog(int id){
如果(id!=对话框\u获取\u谷歌\u播放\u服务){
返回super.onCreateDialog(id);
}
int available=GooglePlayServicesUtil
.isGooglePlayServicesAvailable(此);
如果(可用==ConnectionResult.SUCCESS){
返回null;
}
if(GooglePlayServicesUtil.isUserRecoverableError(可用)){
返回GooglePlayServicesUtil.getErrorDialog(可在,
请求\代码\获取\谷歌\播放\服务,这);
}
返回新的AlertDialog.Builder(此)
.setMessage(R.string.plus_generic_error).setCancelable(true)
.setOnCancelListener(this.create();
}
@凌驾
受保护的void onStart(){
super.onStart();
mpluclient.connect();
}
@凌驾
SaveInstanceState上受保护的无效(束超出状态){
super.onSaveInstanceState(超出状态);
outState.putBoolean(状态解析错误,mResolvingError);
}
@凌驾
受保护的void onStop(){
super.onStop();
mpluclient.disconnect();
}
@凌驾
public void onPeopleLoaded(连接结果状态,
PersonBuffer PersonBuffer,字符串nextPageToken){
开关(status.getErrorCode()){
案例连接Result.SUCCESS:
mListItems.clear();
试一试{
int count=personBuffer.getCount();
Log.e(“,”count:“+count”);
for(int i=0;i
在上面的代码中,它mpluclient.loadVisiblePeople(这个,null);
加载所有可见(圈内)的人..我想加载我圈内的一个特定的人。和mpluclient.loadPeople(这个,“103193341800315457743”);
这可以加载特定的人,但我怎么知道呢