0
私はユーザーが彼の詳細を編集テキストで入力し、サーバーに登録要求を送信し、サーバーの応答が成功した後にダイアログが開き、ユーザーが確認を必要とするアプリケーションを持っています。このデバイスが飛行機モードにあるかどうかを確認したいそれ以外の場合はDismissダイアログを移動して、サーバーにユーザーの詳細を送信します。アプリが飛行機モードにある場合、ダイアログを閉じますか?
コード: - ここ
private final BroadcastReceiver m_oAIRPLANE_MODE_CHECKER = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
otpRequest();
}
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate..............");
setContentView(R.layout.registration_screen);
defaultConfigration();// defining default configuration
init();// Initialize controls
/*Registered Broadcast receiver*/
IntentFilter m_intentFilter = new IntentFilter();// creating object of Intentfilter class user for defining permission
m_intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");// action to check Internet connection
getApplicationContext().registerReceiver(m_oInternetChecker, m_intentFilter);// register receiver....
m_oAirplaneModeIntent = new IntentFilter();
m_intentFilter.addAction("android.intent.action.AIRPLANE_MODE");
getApplicationContext().registerReceiver(m_oAIRPLANE_MODE_CHECKER,m_oAirplaneModeIntent);
}
/*Unregistered broadcast receiver*/
@Override
public void onDestroy() {// unregister broadcast receiver ........
super.onDestroy();
Log.i(TAG, "onDestroy.............");
getApplicationContext().unregisterReceiver(m_oInternetChecker);// unregistaer broadcast receiver.
getApplicationContext().unregisterReceiver(m_oAIRPLANE_MODE_CHECKER);
}
私はデバイスがこのスニペットを使用して機内モードであるかどうかをチェックすることができ、チェック
String sourceString = "We will send you a verification SMS to this Number.<br/><br/> <b><font color='#2196F3'>" + s_szResponseMobileNum + "</b> <br/><br/>Please ensure that this number is active on this device.";
m_OTPAlertBuilder = new AlertDialog.Builder(CRegistrationScreen.this, R.style.AppCompatAlertDialogStyle);
m_OTPAlertBuilder.setCancelable(false);
m_OTPAlertBuilder.setMessage(Html.fromHtml(sourceString));
m_OTPAlertBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
/*This method send request to server to generate OTP*/
/* condition to check whether app is in background*/
if (NetworkUtil.isAppIsInBackground(getApplicationContext())) {
/*if app is in background then start service*/
Intent i = new Intent(CRegistrationScreen.this, OtpGenrateService.class);
getApplicationContext().startService(i);
} else {
/*if app is in forground the send data to server*/
/*this method genrate otp */
generateOtp();
}
}
});