Кнопка входа в Facebook не работает
Я использую диалог из моей активности входа в систему. Внутри диалога у меня есть кнопка входа в Facebook (из Facebook SDK lib). Когда я нажимаю на кнопку входа в Facebook, приложение на мгновение переходит на страницу аутентификации Facebook, а затем возвращается в мое приложение, но на самом деле ничего не происходит.
моя деятельность
public class LoginActivityNew extends FragmentActivity implements OnClickListener{
ViewPager pager;
LoginPagerAdapter pagerAdapter;
Button join, login;
UiLifecycleHelper uiHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
pagerAdapter = new LoginPagerAdapter(getSupportFragmentManager());
pager = (ViewPager) findViewById(R.id.login_pager);
pager.setAdapter(pagerAdapter);
join = (Button) findViewById(R.id.login_join_now_button1);
login = (Button) findViewById(R.id.login_login_button2);
join.setOnClickListener(this);
login.setOnClickListener(this);
} //end of onCreate
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.login_join_now_button1: //JOIN BUTTON
DialogLoginSignup singupDialog = new DialogLoginSignup(this, R.style.DialogTheme);
singupDialog.show();
singupDialog.init(singupDialog);
break;
case R.id.login_login_button2: //LOGIN BUTTON
DialogLoginWelcome loginDialog = new DialogLoginWelcome(this, R.style.DialogTheme);
loginDialog.show();
loginDialog.init(loginDialog);
break;
}
}
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
//Log.d("ohad", "Facebook session opened.");
} else if (state.isClosed()) {
//Log.d("ohad", "Facebook session closed.");
}
}
};
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onSaveInstanceState(Bundle savedState) {
super.onSaveInstanceState(savedState);
uiHelper.onSaveInstanceState(savedState);
}
private class LoginPagerAdapter extends FragmentPagerAdapter{
public LoginPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return new FragmentLogin1();
case 1:
return new FragmentLogin2();
case 2:
return new FragmentLogin3();
}
return null;
}
@Override
public int getCount() {
return 3;
}
}
}
мой диалог
public class DialogLoginWelcome extends Dialog implements OnClickListener, IUserLoginListener, TimelineListener{
TextView join, forgot;
EditText email, password;
Button login;
LoginButton facebook;
Boolean state;
String fbEmail, fbPass;
Calendar cal;
Session session;
IUserLoginListener mIUserLoginListener;
UserLoginHelper mUserLoginHelper;
Context context;
public DialogLoginWelcome(Context context) {
super(context);
this.context = context;
}
public DialogLoginWelcome(Context context, int theme) {
super(context, theme);
this.context = context;
}
public DialogLoginWelcome(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.login_welcome_back);
getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
mIUserLoginListener = this;
}
public void init(DialogLoginWelcome dialog){
join = (TextView) dialog.findViewById(R.id.welcome_join_now_textView3);
forgot = (TextView) dialog.findViewById(R.id.welcome_forgot_textView4);
email = (EditText) dialog.findViewById(R.id.welcome_email_editText1);
password = (EditText) dialog.findViewById(R.id.welcome_password_editText2);
facebook = (LoginButton) dialog.findViewById(R.id.welcome_fb_connect_button1);
login = (Button) dialog.findViewById(R.id.welcome_login_button2);
facebook.setReadPermissions(Arrays.asList("email","public_profile"));
facebook.setSessionStatusCallback(statusCallback);
facebook.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
session = Session.getActiveSession();
Log.d("ohad", "facebook login changed! --- ");
if(user != null){
ProgressBarClass.startLoading(context);
Log.d("ohad", user.toString());
cal = Calendar.getInstance();
mUserLoginHelper = new UserLoginHelper(mIUserLoginListener);
mUserLoginHelper.postUserDetails(user.getProperty("email").toString().trim(), user.getId().trim());
}
}
});
join.setOnClickListener(this);
forgot.setOnClickListener(this);
login.setOnClickListener(this);
//email.setText("test@infibond.com");
//password.setText("a");
//email.setText("naamaraviv@walla.co.il"); //Production
//password.setText("naama1978raviv");
//email.setText("kraus@infibond.com"); //Dev
//password.setText("kraus246");
//email.setText("ohadshiffer28@walla.co.il"); //Production
//password.setText("1234");
email.setText("noam@infibond.com"); //Production & Dev
password.setText("nl555");
//email.setText("max@wsiseo.co.il"); //Production
//password.setText("wsi768");
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.welcome_join_now_textView3: //JOIN
dismiss();
DialogLoginSignup dialog = new DialogLoginSignup(context, R.style.DialogTheme);
dialog.show();
dialog.init(dialog);
break;
case R.id.welcome_forgot_textView4: //FORGOT
//context.startActivity(new Intent(context, ForgotPassActivity.class));
break;
case R.id.welcome_fb_connect_button1: //FACEBOOK
break;
case R.id.welcome_login_button2: //LOGIN
//VALIDATION OF INPUT SCREEN
//IF FIELDS ARE EMPTY - SHOW ALERT MESSAGE.
if (email.getText().toString().equals("")|| password.getText().toString().equals("")){
Alert_Dialog.showAler(context, "Enter the required fields.", "Error!");
}
else { //IF FIELDS AREN'T EMPTY
state = Utility.isOnline(context);
if (state == true) {
ProgressBarClass.startLoading(context);
new UserLoginHelper(this).postUserDetails(email
.getText().toString().trim(), password
.getText().toString().trim());
} else if (state == false) {
Alert_Dialog.showAler(context, "Check Internet Connection", "Network Error!");
}
}
break;
}
}
@Override
public void onUserLoginError(String errorMsg) {
ProgressBarClass.dismissLoading();
Alert_Dialog.showAler(context, errorMsg, "Error");
}
@Override
public void onUserLoginSuccess(String response) {
JSONObject res;
try {
res = new JSONObject(response);
Constant.me.setName(res.getString("full_name"));
Constant.me.setEmail(res.getString("email"));
Constant.me.setFirstName(res.getString("first_name"));
Constant.me.setLastName(res.getString("last_name"));
Constant.me.setBirth_date(res.getString("birthday"));
Constant.me.setBody_value(res.getString("bio"));
Constant.me.setProfileImageUrl(res.getString("picture"));
Constant.me.setPrivacy(res.getString("privacy"));
Constant.me.setPermissions(res.getString("permissions"));
Constant.me.setUid(res.getString("uid"));
Constant.me.setRelationship("self");
} catch (JSONException e) {
e.printStackTrace();
} finally{
new TimeHelper(this).getAlbumDetails(Constant.INFIBOND_DEV_SERVER_URL +
"timeline/get?uid=" + Constant.me.getUid() +
"&userType=user" +
"&storiesLimitPerYear=6");
}
}
@Override
public void onTimelineError(String errorMsg) {
ProgressBarClass.dismissLoading();
Alert_Dialog.showAler(context, errorMsg, "Error");
}
@Override
public void onTimelineSuccess(String response) {
JSONObject res = null;
try {
res = new JSONObject(response);
} catch (JSONException e) {
e.printStackTrace();
}
Intent intent = new Intent(context, MyInfiActivity.class);
intent.putExtra("moments", res.toString());
context.startActivity(intent);
ProgressBarClass.dismissLoading();
((Activity) context).finish();
}
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.d("ohad", "Facebook session opened. 3");
} else if (state.isClosed()) {
Log.d("ohad", "Facebook session closed. 3");
}
}
};
}