混合移动应用程序(C#和Bootstrap)

时间:2016-03-09 07:06:04

标签: c# google-play internet-connection

我使用C#Bootstrap开发了混合移动应用程序,我在Google Play上发布了它并且工作正常,但是当用户在没有互联网连接时尝试打开应用程序时,出现一条消息“网页不可用”HTTP:// ...的网页可能暂时关闭或......

问题是:如何避免此消息或如何使用我的消息或web form自定义此消息?

1 个答案:

答案 0 :(得分:0)

试试此代码。首先使用WebClient&检查互联网连接。如果连接不可用,则返回自定义页面。

public void MyMethod()
        {
            if (CheckInternetConnection() == false)
            {
                Response.Redirect("custompage.aspx");
            }
            else
            {
                //your application method
            }
        }

        public bool CheckInternetConnection()
        {
            try
            {
                using (var obj = new WebClient())
                {
                    using (var stream = obj.OpenRead("http://www.google.co.in"))
                    {
                        return true;
                    }
                }
            }
            catch
            {
                return false;
            }
        }
相关问题