我想在我的Android应用程序中显示警告对话框,如果网络或GPS被禁用,怎么可能。请帮助我,我是Android的新手
答案 0 :(得分:0)
您需要使用广播接收器进行网络状态更改& gps连接状态更改,请参阅:Check INTENT internet connection和How can I check the current status of the GPS receiver?
答案 1 :(得分:0)
测试GPS是否启用的功能(布尔返回)是:
ConnectivityManager conMgr = ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMgr.getActiveNetworkInfo();
if (netInfo == null){
Description.setVisibility(View.INVISIBLE);
new AlertDialog.Builder(WelcomePage.this)
.setTitle(getResources().getString(R.string.app_name))
.setMessage(getResources().getString(R.string.internet_error))
.setPositiveButton("OK", null).show();
}else{
dialog = ProgressDialog.show(WelcomePage.this, "", "Loading...", true,false);
new Welcome_Page().execute();
}
确定是否启用了网络(包括对话框):
WKWebView
Android - Programmatically check internet connection and display dialog if notConnected