1

Я хочу проверить мобильный номер, введенный пользователем в виде EditText, когда пользователь нажимает кнопку входа в FB. Без действительного мобильного телефона ни один пользователь не может войти в систему.Проверка правильности просмотра EditText при нажатии кнопки входа в FB

У меня есть кнопка входа в FB и вид EditText как в фрагменте MainActivity. Прошу помочь, я все пробовал.

ContactDetail.java

public class ContactDetail extends ActionBarActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_contact_detail); 

    //Code for adding permanent '+91' at starting of Mobile No text field 
    final EditText edt = (EditText) findViewById(R.id.edit_text_mobileno); 

    //Default text of the field 
    edt.setText("+91 "); 
    Selection.setSelection(edt.getText(), edt.getText().length()); 

    edt.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, 
             int after) { 
      // TODO Auto-generated method stub 
     } 

     //Adding +91 as permanent text 
     @Override 
     public void afterTextChanged(Editable s) { 
      if (!s.toString().startsWith("+91 ")) { 
       edt.setText("+91 "); 
       Selection.setSelection(edt.getText(), edt.getText().length()); 

      } 

     } 
    }); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

ContactDetailFragment.java

public class ContactDetailFragment extends Fragment { 

private TextView textDetail; 
private CallbackManager mCallbackManager; 
private AccessTokenTracker mTracker; 
private ProfileTracker mProfileTracker; 

private FacebookCallback<LoginResult> mCallback = new FacebookCallback<LoginResult>() { 
    @Override 
    public void onSuccess(LoginResult loginResult) { 
     AccessToken accessToken = loginResult.getAccessToken(); 
     Profile profile = Profile.getCurrentProfile(); 
     displayWelcomeMessage(profile); 
    } 

    @Override 
    public void onCancel() { 

    } 

    @Override 
    public void onError(FacebookException e) { 

    } 
}; 

public ContactDetailFragment() { 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); 
    mCallbackManager = CallbackManager.Factory.create(); 
    //Method to track access token for change in token values provided by FB login 
    mTracker = new AccessTokenTracker() { 
     @Override 
     protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { 
     } 
    }; 
    mProfileTracker = new ProfileTracker() { 
     @Override 
     protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { 
      displayWelcomeMessage(newProfile); 
     } 
    }; 

    //Started Tracking facebook token for FB-Login 
    mTracker.startTracking(); 
    mProfileTracker.startTracking(); 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.fragment_contact_detail, container, false); 
} 

private void displayWelcomeMessage(Profile profile) { 
    if (profile != null) { 
     textDetail.setText("Welcome" + profile.getName()); 
    } 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 


    LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); 
    loginButton.setReadPermissions("user_friends"); 
    loginButton.setFragment(this); 
    loginButton.registerCallback(mCallbackManager, mCallback); 
    textDetail = (TextView) view.findViewById(R.id.text_detail); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    Profile profile = Profile.getCurrentProfile(); 
    displayWelcomeMessage(profile); 
} 

//Stopping the tracking of Facebook token on stopping the app 
@Override 
public void onStop() { 
    super.onStop(); 
    mProfileTracker.stopTracking(); 
    mTracker.stopTracking(); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    mCallbackManager.onActivityResult(requestCode, resultCode, data); 
}} 
+0

Добавлены коды моей основной деятельности (ContactDetail.java) и Фрагмент (ContactDetailFragment.java). Я попытался вызвать метод OnClick на кнопке Fblogin, попытался проверить метод OnSuccess и т. Д., Но ничего не работает. любезную помощь. – lazyanuj

ответ

0

Facebook отключить эту функцию, источник here.

Несмотря на то, что статья довольно старая, похоже, что она не включена.

Смежные вопросы