2015-09-16 3 views
1

Я сделал приложение, в котором пользователь сначала проверяет его номер с помощью проверки sinch, а затем после успешной проверки он переходит в игру, но проблема в том, что каждый раз, когда пользователь открывает приложение, он или она должна снова проверить, что очень плохо.Sinch mobile verification Пропуск

я не как о пропустить процесс проверки после того, как снова открыть приложение

Основная деятельность

public class MainActivity extends Activity { 

    public static final String SMS = "sms"; 
    public static final String FLASHCALL = "flashcall"; 
    public static final String INTENT_PHONENUMBER = "phonenumber"; 
    public static final String INTENT_METHOD = "method"; 

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

     setContentView(R.layout.activity_main); 

     TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 

     TextView phoneNumber = (TextView) findViewById(R.id.phoneNumber); 
     phoneNumber.setText(manager.getLine1Number()); 
    } 

    private void openActivity(String phoneNumber, String method) { 
     Intent verification = new Intent(this, VerificationActivity.class); 
     verification.putExtra(INTENT_PHONENUMBER, phoneNumber); 
     verification.putExtra(INTENT_METHOD, method); 
     startActivity(verification); 
    } 

    private boolean checkInput() { 
     TextView phoneNumber = (TextView) findViewById(R.id.phoneNumber); 
     if (phoneNumber.getText().toString().isEmpty()) { 
      Toast.makeText(this, "Please input a phone number.", Toast.LENGTH_LONG).show(); 
      return false; 
     } 
     return true; 
    } 

    public void onButtonClicked(View view) { 
     if (checkInput()) { 
      TextView phoneNumber = (TextView) findViewById(R.id.phoneNumber); 
      if (view == findViewById(R.id.smsVerificationButton)) { 
       openActivity(phoneNumber.getText().toString(), SMS); 
      } else if (view == findViewById(R.id.callVerificationButton)) { 
       openActivity(phoneNumber.getText().toString(), FLASHCALL); 
      } 
     } 
    } 

} 

деятельность по проверке

public class VerificationActivity extends Activity { 

    private static final String TAG = Verification.class.getSimpleName(); 
    private final String APPLICATION_KEY = "af23************************"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_verification); 
     ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressIndicator); 
     progressBar.setVisibility(View.VISIBLE); 

     Intent intent = getIntent(); 
     if (intent != null) { 
      String phoneNumber = intent.getStringExtra(MainActivity.INTENT_PHONENUMBER); 
      String method = intent.getStringExtra(MainActivity.INTENT_METHOD); 
      TextView phoneText = (TextView) findViewById(R.id.numberText); 
      phoneText.setText(phoneNumber); 
      createVerification(phoneNumber, method); 
     } 

    } 

    void createVerification(String phoneNumber, String method) { 
     Config config = SinchVerification.config().applicationKey(APPLICATION_KEY).context(getApplicationContext()) 
       .build(); 
     VerificationListener listener = new MyVerificationListener(); 
     Verification verification; 
     if (method.equalsIgnoreCase(MainActivity.SMS)) { 
      verification = SinchVerification.createSmsVerification(config, phoneNumber, listener); 
     } else { 
      TextView messageText = (TextView) findViewById(R.id.textView); 
      messageText.setText(R.string.flashcalling); 
      verification = SinchVerification.createFlashCallVerification(config, phoneNumber, listener); 
     } 
     verification.initiate(); 
    } 

    class MyVerificationListener implements VerificationListener { 

     @Override 
     public void onInitiated() { 
      Log.d(TAG, "Initialized!"); 
     } 

     @Override 
     public void onInitiationFailed(Exception exception) { 
      Log.e(TAG, "Verification initialization failed: " + exception.getMessage()); 
      hideProgress(R.string.failed, false); 
     } 

     @Override 
     public void onVerified() { 
      Log.d(TAG, "Verified!"); 
      hideProgress(R.string.verified, true); 
     } 

     @Override 
     public void onVerificationFailed(Exception exception) { 
      Log.e(TAG, "Verification failed: " + exception.getMessage()); 
      hideProgress(R.string.failed, false); 
     } 
    } 

    void hideProgress(int message, boolean success) { 
     if (success) { 
      ImageView checkMark = (ImageView) findViewById(R.id.checkmarkImage); 
      checkMark.setVisibility(View.VISIBLE); 
     } 
     ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressIndicator); 
     progressBar.setVisibility(View.INVISIBLE); 
     TextView progressText = (TextView) findViewById(R.id.progressText); 
     progressText.setVisibility(View.INVISIBLE); 
     TextView messageText = (TextView) findViewById(R.id.textView); 
     messageText.setText(message); 
    } 

} 

Я просто хочу, чтобы на повторное открытие процесс проверки не должен снова вызываться.

+1

Вы можете использовать 'SharedPreferences' для локального управления, если пользователь проверен или нет –

+0

Я не знаю, как t o использовать его? любой пример? –

+0

учебники по общим предпочтениям https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=shared%20preference%20example – Shruti

ответ

1

Вы можете использовать SharedPreferences. добавьте key в свой объект SharedPreferences и инициализируйте значением 0. Вы можете сделать что-то вроде ниже

SharedPrefences prefences = PrefenceManager.getSharedPreferences("TAG",Context.MODE_PRIVATE); 

SharedPreferences.Editor editor = preferences.edit(); 

Сейчас на преуспевающей проверке:

preferences.putInt("key",1); 

так на следующей проверке запуска для этого key значения, если его 1 пропустить VerificationActivity и начать GameActivtiy т.е.

int value = preferences.getInt("key",0); 

if(value == 0){ 
    // Verify 
}else{ 
    // Skip Verification 
} 
+0

Спасибо, всего лишь секунда, я пытаюсь нормально –

+0

Спасибо, что это сработало .... –