0
我正在開發一個用戶可以連接到Facebook的android應用程序。我可以登錄並獲取配置文件信息,但是當我傳遞給另一個片段並返回登錄片段時,用戶提醒連接,但我看不到配置文件信息。當我傳遞或更改片段時如何保持這些信息可見?登錄facebook sdk 4.0.1與android應用程序
這是我的代碼:
public class Share extends Fragment {
LoginButton loginButton;
TextView nameT,emailT,locationT,idT,msginfo;
ProfilePictureView ppv;
CallbackManager callbackManager;
private ShareDialog shareDialog;
File destination;
String imagePath;
Bitmap bmp;
ImageView takePhoto,preview;
private static final int REQUEST_IMAGE = 100;
RelativeLayout otherview;
AccessTokenTracker accessTokenTracker;
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
@Override
public void onActivityResult(int requestCode, int responseCode, Intent data)
{
super.onActivityResult(requestCode, responseCode, data);
callbackManager.onActivityResult(requestCode, responseCode, data);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.share, container, false);
super.onCreate(savedInstanceState);
loginButton = (LoginButton)view.findViewById(R.id.authButton);
nameT= (TextView)view.findViewById(R.id.name);
locationT= (TextView)view.findViewById(R.id.location);
emailT= (TextView)view.findViewById(R.id.mail);
idT=(TextView)view.findViewById(R.id.id);
ppv = (ProfilePictureView)view.findViewById(R.id.fbimg);
otherview=(RelativeLayout)view.findViewById(R.id.other_views);
msginfo=(TextView)view.findViewById(R.id.msginfo);
List<String> permissionNeeds = Arrays.asList("user_photos", "email", "user_birthday", "user_location", "public_profile");
loginButton.setReadPermissions(permissionNeeds);
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
{
@Override
public void onSuccess(LoginResult loginResult)
{
System.out.println("onSuccess");
msginfo.setText("You can now share image on facebook");
otherview.setVisibility(View.VISIBLE);
GraphRequest request = GraphRequest.newMeRequest
(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback()
{
@Override
public void onCompleted(JSONObject object, GraphResponse response)
{
// Application code
Log.v("LoginActivity", response.toString());
//System.out.println("Check: " + response.toString());
try
{
String id = object.getString("id");
idT.setText(object.getString("id"));
ppv.setProfileId(object.getString("id"));
nameT.setText(object.getString("name"));
emailT.setText(object.getString("email"));
locationT.setText(object.getString("address"));
String name = object.getString("name");
String email = object.getString("email");
String gender = object.getString("gender");
String birthday = object.getString("birthday");
// String location = object.getString("location");
// String location = object.getString("user_location");
// String location = object.getString("address");
System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + birthday);
// locationT.setText(location);
}
catch (JSONException e)
{
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday,link");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel()
{
System.out.println("onCancel");
}
@Override
public void onError(FacebookException exception)
{
System.out.println("onError");
Log.v("LoginActivity", exception.getCause().toString());
}
});
return view;
}
}
我會嘗試一下謝謝 – user3921905
怎麼樣的profilepicture我可以保存嗎? – user3921905
您可以保存任何實現Parcelable接口的類的對象。然而,這是另一個討論的話題。 – rasmeta