connectivity

Pausing service until internet connection can be established

余生长醉 提交于 2019-12-05 00:35:40
问题 I have a service that runs upon boot completion. This service requires internet connectivity. What's the best practice for waiting for the device to connect to the internet? Mobile of wifi doesn't really matter. My current solution involves a while loop that just checks ConnectivityManager until one of the networks becomes available, but this feels vulgar. Is there a better way to do this? 回答1: but this feels vulgar Indeed :D Your receiver wakes your wakeful intent service (probably a simple

How to change the network state of device from source code in Android?

烂漫一生 提交于 2019-12-04 14:53:51
问题 I am trying to change the network state of the device from the source code. I observed that there is a permission to grant to the applications for changing the network state i.e., CHANGE_NETWORK_STATE. But I am not able to find any example or code that can change the network state of a device. Please let me know if anyone knows or have an example to change the network state of a device. Regards, SSuman185 回答1: This code is working. I got it from here. private void setMobileDataEnabled(Context

How to check url is loaded in webview or not

筅森魡賤 提交于 2019-12-04 11:46:32
I am loading url in android webview using below code webviewShowPost.loadUrl(URL); I want to check if no data connectivity available then webview instead of showing blank view, I can display Toast of no connectivity. Thanks public static boolean isOnline(Context context) { try { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo().isConnectedOrConnecting()) { URL url = new URL("http://www.google.com.pk/"); HttpURLConnection urlc = (HttpURLConnection) url .openConnection(); urlc.setConnectTimeout(1000); // mTimeout

Detecting “use only 2G networks” setting

ぐ巨炮叔叔 提交于 2019-12-04 11:40:40
问题 Is there a way of returning the value of Android's mobile network setting for "use only 2G networks"? The app being developed measures the internet speed at a certain location, but in order for this to be relevant, it must know if the user is deliberately restricting mobile internet to 2G. I've taken a look at ConnectivityManager, but it only provides information about the background data setting or all networks. Iterating through them reveals that despite the setting being enabled, HSPA and

How to check if internet is available or not in app startup in android?

元气小坏坏 提交于 2019-12-04 11:24:49
问题 My app at first loads the datas from internet(I am using webservice) I want to check internet access at app startup. I will like to check if any forms of internet either 3G or WIFI or GPRS or any other is available or not. If not available, give message to user like " You need internet access " and exit the app. (Currently i am getting force close error in my app if there is no internet access) If availabe, start my app normally. Also, my app is fetches the datas from webservice at different

Is it possible to detect LTE connection using iOS SDK?

孤人 提交于 2019-12-04 08:54:24
问题 I'm using the reachability API to detect my current connection, but I can only distinguish between WIFI and 3G. I get the following flags: LTE: kSCNetworkReachabilityFlagsIsLocalAddress|kSCNetworkReachabilityFlagsIsWWAN|kSCNetworkReachabilityFlagsTransientConnection|kSCNetworkReachabilityFlagsReachable WIFI: kSCNetworkReachabilityFlagsIsDirect|kSCNetworkReachabilityFlagsReachable The problem is that LTE returns the same flags as a 3G connection. Is there any way to determine whether the user

Unable to access Internet via WiFi from a Background service

依然范特西╮ 提交于 2019-12-03 15:29:22
I'll get straight onto some facts/figures I discovered pls help me if you've faced/solved a similar problem. I send back data every 5 minutes to a server unless the user manually toggles it Off with the help of a wakeful broadcast receiver through a intent service . Plus I get wifi locks before doing (I've tried this already without locks; doesnt work either) Now on devices sending back data from regular data networks (2G/3G/4G) this works fine but on those connected to a wifi network somehow gets me a getActiveNetworkInfo() as null (Even directly hitting the web URL gives a hostname not found

Pausing service until internet connection can be established

自古美人都是妖i 提交于 2019-12-03 15:16:49
I have a service that runs upon boot completion. This service requires internet connectivity. What's the best practice for waiting for the device to connect to the internet? Mobile of wifi doesn't really matter. My current solution involves a while loop that just checks ConnectivityManager until one of the networks becomes available, but this feels vulgar. Is there a better way to do this? Mr_and_Mrs_D but this feels vulgar Indeed :D Your receiver wakes your wakeful intent service (probably a simple intent service would do, as the phone does not sleep while booting AFAIK) service registers a

Objective-C/iOS: Keeping bluetooth connection alive in the background

天大地大妈咪最大 提交于 2019-12-03 09:47:26
问题 I've been researching this for a couple of days now and looks like it's not possible to keep bluetooth connection alive while the phone goes to sleep or if the app is in the background. However, I have found one app that claims they can run all the time: RunKeeper app says: What's New In Version 2.5.1.0 Support for tracking heartrate in the background with Wahoo heartrate monitor. Does anyone know how they manage to send heart rate data to the phone while the app is in the background? UPDATE:

How to change the network state of device from source code in Android?

独自空忆成欢 提交于 2019-12-03 09:14:33
I am trying to change the network state of the device from the source code. I observed that there is a permission to grant to the applications for changing the network state i.e., CHANGE_NETWORK_STATE. But I am not able to find any example or code that can change the network state of a device. Please let me know if anyone knows or have an example to change the network state of a device. Regards, SSuman185 Suman This code is working. I got it from here . private void setMobileDataEnabled(Context context, boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager) context