简体   繁体   English

如何检查安卓设备是否有来自服务器的互联网连接?

[英]How to check if android device is having a internet connection from server?

I am making an android application where I need to check whether an android device is having an active internet connection or not.我正在制作一个 android 应用程序,我需要检查一个 android 设备是否有活动的互联网连接。 I can do that from an application but how do I check it from the server without touching an android device?我可以从应用程序中做到这一点,但如何在不接触 android 设备的情况下从服务器检查它?

Option 1: Make a service that will send the request to a server every 5 mins.选项 1:创建一个服务,每 5 分钟向服务器发送一次请求。 Is it alright or is there any other option?可以吗,或者还有其他选择吗?

public boolean isConnectedToServer(String url, int timeout) {
try{
    URL myUrl = new URL(url);
    URLConnection connection = myUrl.openConnection();
    connection.setConnectTimeout(timeout);
    connection.connect();
    return true;
} catch (Exception e) {
    // Handle your exceptions
    return false;
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android-如何检查设备是否可以连接互联网? - Android - How to check, device has Internet connection? 如何正确检查Android设备上的互联网连接? - How to properly check internet connection on android device? 如何使用 android 中的互联网连接检查手机检查服务器连接是否可用? - How to check server connection is available or not with internet connection check mobile in android? 在没有互联网连接的情况下从安卓设备向服务器发送消息 - Send message to a server from android device without internet connection 如何将数据从本地服务器推送到Android设备-没有GCM,没有Internet连接 - How to push data from local server to Android Device - No GCM, No Internet Connection 如何创建从本地服务器到 Android 设备的推送通知 - 没有 GCM,没有互联网连接 - How to Create push notofication from local server to Android Device - No GCM, No Internet Connection 如何检查Android中的inter.net连接 - How to check internet connection in Android android:如何知道设备中是否有互联网连接? - android: how to know internet connection is available or not in device? 如何在不使用互联网连接的情况下将android物理应用中的http消息发送到本地服务器? - How can I send http messages from android app( physical device) to my local server without using internet connection? 如何检查android设备是否可以访问互联网? - How to check if android device has access to internet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM