【发布时间】:2016-08-29 13:56:40
【问题描述】:
我有一个应用程序,用户在编辑文本中输入他的详细信息并向服务器发送注册请求,在服务器成功响应后,将打开一个对话框,需要用户在这里确认我想检查设备是否处于飞行模式,如果是,然后移动关闭对话框,否则将用户详细信息发送到服务器。
代码:-
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();
}
}
});
【问题讨论】:
标签: android