lundi 30 mars 2015

Facebook SDK 4 in Android Studio ExceptionInitializeError Login v2.3

First and foremost could someone provide me a sample that just connects and switch to another fragment when logged in that would be great so I'll have working code I can look at to understand. I'm just trying to put a Login button on a test page when the user is connected with facebook then the fragment should change. I tried what's there : http://ift.tt/1GtHi9L but I can't get it working and don't really understand what's going on.. So I'm lost. I'm having a ExceptionInitializeError with the following code. But I doubt it is correct.


My login fragment:



public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login_frag, container, false);

loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setFragment(this);

// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getActivity(),"Success",Toast.LENGTH_SHORT).show();
}

@Override
public void onCancel() {
Toast.makeText(getActivity(),"fail",Toast.LENGTH_SHORT).show();
}

@Override
public void onError(FacebookException exception) {
Toast.makeText(getActivity(),"error",Toast.LENGTH_SHORT).show();
}
});
return view;
}


MainActivity:



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
monFragmentManager = new MonFragmentManager(getSupportFragmentManager());
monFragmentManager.showFragment(0, false);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
monFragmentManager.showFragment(1,false);
}

@Override
public void onCancel() {
monFragmentManager.showFragment(0,false);
}

@Override
public void onError(FacebookException e) {
monFragmentManager.showFragment(0,false);
}
});
}

Aucun commentaire:

Enregistrer un commentaire