recently I have WI-FI connecter code . and I add if wi-fi connect button click, showing dialog. but showing dialog continued remains. I want when WI-FI connecting showing dialog, and completed wifi connect ,dismiss dialog.
I try this. but is I don't know error logcat.
How programatically showing progress dialog when wifi connecting ?
@Override
public void onClick(View v) {
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
boolean connResult = false;
if (config != null) {
connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false); //WI-FI 연결
final Dialog dialog = new Dialog(v.getContext());
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
dialog.setContentView(R.layout.dialog);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
ConnectivityManager manager = (ConnectivityManager)getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); //NullPointerException this line
NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(wifi.isConnected()){
dialog.dismiss();
}else {
dialog.show();
}
}
if (!connResult) {
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
}
}
};
- try
Context context; //global variable
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); //Null pointer Exception
NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(wifi.isConnected()){
dialog.dismiss();
}else {
dialog.show();
}
please perhaps need information, advice for me thanks .