如果我的android webview中没有互联网可用,如何显示消息 [英] How to show message if no internet available in my android webview

查看:130
本文介绍了如果我的android webview中没有互联网可用,如何显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用android webview应用程序。我在应用程序中成功使用了我的url,并且只有在可以连接互联网的情况下它才能正常工作。但是我想在没有互联网连接时显示一些消息。我该怎么办?自从我是android开发新手以来,请帮助我,谢谢:)

Hi I am working with android webview application.I uses my the url succesfully in my app and it works only if internet connection available .But I want to show some messages when there is no internet connection.how can i do this ???please help me since I am new to android development and thanks :)

推荐答案

在打开<$ c之前调用此方法$ c> webView 如果此方法返回true ,这表示互联网连接可用,并且您可以处理webview否则,显示一些 Toast ,或者如果此方法返回false 对话框 $ c>。

Call this method before opening the webView if this method returns true that means the internet connection is avialable and you can process to the webview otherwise show some Toast or you can show Dialog if this method returns false.

编辑

在您的主要活动

if(isNetworkStatusAvialable (getApplicationContext())) {
    Toast.makeText(getApplicationContext(), "internet avialable", Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(getApplicationContext(), "internet is not avialable", Toast.LENGTH_SHORT).show();

}

方法

public static boolean isNetworkStatusAvialable (Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) 
    {
        NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
        if(netInfos != null)
        if(netInfos.isConnected()) 
            return true;
    }
    return false;
}

这篇关于如果我的android webview中没有互联网可用,如何显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆