启动画面活动是全屏的,我正在使用以下链接检查互联网连接:
http://www.androidhive.info/2012/07/android-detect-internet-connection-status/
我已经为alertdialog RETRY和CLOSE实现了2个按钮。在关闭点击我终止应用程序。 在重试时单击呼叫功能以检查互联网连接。 当我尝试通过拉下设备的操作栏/状态栏来连接到互联网时,警报对话框就会消失。
我的互联网检查功能在oncreate函数的setcontentview之后调用。
以下是我的代码:
Inside on create function
cd = new ConnectionDetector(getApplicationContext());
checkInternet();
public void checkInternet()
{
Log.i("INTERNET CONNECTION CHECKING", "CHECKING INTERNET CONNECTION");
// get Internet status
isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent)
{
// Internet Connection is Present
// make HTTP requests
//showAlertDialog(SplashScreenActivity.this, "Internet Connection", "You have internet connection", true);
}
else
{
// Internet connection is not present
// Ask user to connect to Internet
showAlertDialog(SplashScreenActivity.this, "No Internet Connection",
"Please Retry or close.", false);
}
}
public void showAlertDialog(Context context, String title, String message, Boolean status)
{
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting alert dialog icon
//alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,"RETRY", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
checkInternet();
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,"CLOSE", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
//finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
// Showing Alert Message
alertDialog.show();
}
答案 0 :(得分:1)
尝试删除启动画面的全屏模式,这样您就可以直接访问设备的状态栏