HttpUrlConnection on Android Wear with connected phone - httpurlconnection

I am trying to access the network with my Android Wear 2.0 App.
The Problem:
If the smartwatch is connected with the phone then I get an connection timeout. But if the smartwatch isnĀ“t connected with the phone then the connection works fine.
I am using HttpUrlConnection.
Thanks and sorry for my bad english!

This has been answered in a different post:
Android Wear 100% packet loss
The basic idea is that you should not count on having Wi-Fi on the watch. The user may disable Wi-Fi on the watch and then your application will not work on the watch. Instead you should use your companion phone app to connect to the internet. If the phone isn't connected to your watch then use Wi-Fi.
Even if you want your app to run on an LET enabled watch the user may have turned this off or may not have a SIM card installed. At this point the user will most likely still expect your app to work.
So depending on what it is you're working on, if you want your app to work even while connected to the phone, then make a companion app for the phone. If you want your watch app to be a stand-alone app but you still want to be able to access the internet even when the watch is connected to the phone then you're basically saying that you want to drain the user's battery by using Wi-Fi/LTE instead of going via Bluetooth through the phone to access the web.

Related

Core Bluetooth: Cannot find a BLE device in the app again if reinstalling the app without disconnecting the BLE device properly in the app

When I reinstall the app without disconnecting the BLE device, the phone keeps the connection so when I reinstall my app and scan for a BLE device, the last connection will appear in os level, but not in-app level. This causes me to not discover a BLE device if it is not disconnected on the app properly before. My tester insists that if I reinstall the app, I should not see a connection and discover the BLE device anyways.
I can retrieve a BLE device connection in the app if I know the UUID and services, but it is impossible without these as I see in the documentation. Is there any other way to resolve this problem?
This is precisely what retrieveConnectedPeripherals(withServices:) is for. That will return already connected (at the OS level) peripherals that advertise a particular list of services.
You will still need to call connect on the returned peripherals. "Connect" in this context means "to the app," not "to the device." The docs refer to these "app" connections as "local."

Third party apps in Apple Watch without internet

I'm trying to compare the possibilities of use beetween Apple WatchOS and Android Wear when it comes to using them without the phone nearby. And without conection to internet (Wi-Fi).
I own a Android Wear and have tested the possibilities but cant get an Apple Watch and all the info I can find is this: https://support.apple.com/en-us/HT205547
It says that with wifi you can: Use apps that support Wi-Fi. But what does it mean to support Wi-Fi? Does that mean third party apps cannot be used without internet in any case?
Thanks very much for the help!
Third party apps can run on watchOS without a network connection even if the Watch is not connected to the paired iPhone.
That piece of documentation you linked is only showing which system apps can be used without being connected to an iPhone with/without network connection.
If your watchOS app is not network based, it can fully function even when the Watch is not connected to the iPhone and there are no known Wifi networks available.

iOS 7 Bluetooth - app that handles events in background even after phone restart

I want to write a tracking application, which reacts/record when users get in a car and phone automatically pair with Bluetooth hands free. I need also Id of the hands free device.
On Android it is easy, using Broadcast Receiver your app listen to broadcasts that device had been paired with phone. It is working even after phone had been restarted and App did not run after restart.
Is it possible on iOS(7+) ?
You can do it by reading the "Performing Long-Term Actions in the Background" part of this docs
Essentially, using state restoration, the system takes note of what your app was doing when it was killed.
If the app is searching for a bluetooth device and is killed by the system, the system will take care of continuing this research and wake up the app again when the bt device has ben found.
Note that this will work only if the app is killed by the system, not by the user (using the multitask bar). This behavior has changed since iOS 7.
Alternatively, If your BT hardware can be programmed to send advertisements using the ibeacon protocol, your app can be "awakened" by the corelocation/ibeacon api. After that prompt then maybe the corebluetooth pairing code could be initiated.

How to change connection from 3G to wi-fi programmatically using iPhone SDK?

Lets consider that I am connected to internet through 3G in my App. When a wi-fi hot spot seems to be appearing, can I programmatically switch to the wi-fi. Is this vice-versa condition possible?
iOS does this automatically by itself!
If no known WiFi network is found, it uses cellular data. If it finds a known WiFi-network, it connects to and uses that network instead.
If any WiFi-network is found, and your application requests access to the internet, iOS (usually) automatically presents an alertView and lets the user log in to a WiFi-network. If the user does not log into a WiFi-network, it stays on the 3G-network. When iOS 7 comes, iOS may connect to Hotspot 2.0 networks automatically as well.
Apple keeps individual apps on a tight leash, and so they do not let apps control things like this.

Any iPhone SDK API available to promote 3G/GPRS over WiFi in an iPhone application

I have a requirement to promote 3G/GPRS over WiFi connectivity in the iPhone application I am developing. Please let me know if this is possible and if yes, how?
The problem is when I have a WiFi network which is available and connected but not logged in using Captive Portal, I cannot use that WiFi network to perform the tasks which require internet connection. What i have noticed is Reachability API detects the available WiFi but I cannot use it as I am not logged in and so I am not connected to internet using this WiFi hotspot until I login. So I want to use 3G/GPRS to perform the tasks requiring internet connectivity.
iPhone's default behavior is it uses WiFi when its available and if not then only 3G/GPRS.
So please let me know if both 3G/GPRS and WiFi are available but I am connected to internet not using WiFi but 3G/GPRS how to use 3G/GRPS to perform the tasks requiring internet connectivity.
Regards,
Third-party applications don't get control of where their data comes from. About all you're going to be able to do is ask your users to turn wifi off while your application does its thing. If you need to get back onto wifi after doing the initial data transfer, you could make some clever use of the iOS 4 multitasking and local-notification APIs: when your application enters the background, it could start a background-task handler (using -beginBackgroundTaskWithExpirationHandler: in your app delegate's -applicationDidEnterBackground:) to wait for the wifi connection to become unavailable, do its thing with the cell network, then create a UILocalNotification to tell the user it's okay to turn wifi back on again. That way, the user could get the benefits of whatever your app does and still keep the connection they started out on.
If you are creating an app which needs to access certain network resource(s) to function, then you should just ping, or try to connect to those resources directly instead of just depending on reachability for the decision. If you can't ping your server, then have the app do the same thing it would if reachability reported zero connectivity (even though it may not be).
For security reasons, Apple doesn't allow developer to do such settings pro grammatically, despite you GPRS network connection to achieve some purposes.