Andorid Wear - Start Mobile Service on Watch Face Set - android

How do I start a standard Service on my mobile device from a watch face? Would I need to use the Message API? If so, what would be the correct way of doing this? I currently only start the Service on the mobile's boot and when I open the config activity.

Yes, you'll need to use the Message API. You'll find it well documented at https://developer.android.com/training/wearables/data-layer; if you subclass WearableListenerService on the handheld, it will start automatically when a message is sent from the watch. This could be your existing service (just change it from extends Service to extends WearableListenerService), or you could leave your existing service unchanged and start it from the new WearableListenerService when a message arrives.

Related

Start service without activity

Is it possible to start a service without starting an activity? My plan is to write an application which shows a notification when Bluetooth device is connected and a headset
Thanks for answers
Services ONLY can be started from Android components , such as Activity , BroadcastReceiver and either from another service. Anyway to start a service you need a Context , Because you're gonna call Context.startService(i).
In your case I suggest you to start your service from a BroadcastReceiver as same as this one :
How to detect when a user plugs headset on android device? (Opposite of ACTION_AUDIO_BECOMING_NOISY)

Activity Recognition when the app is not running?

In the demo video provided by google, it is said that you don't need to keep a service running to receive updates on activity recognition. But all code examples I could find show that you need to register ActivityRecognition in MainActivity for it to work.
How can I make Activity Recognition independent of application lifecycle?
For e.g. If a user is jogging, show him a notification to record his walk?
Can it work similar to a broadcast receiver which is called as soon a user is connected to wifi?
As an example you could subscribe to ActivityRecognition events when your phone booted successfully. You only need to do it once. After that the PendingIntent is called in the specified interval and you do not need to have a service running all the time in the background.

How android chat applications (Watsapp, Hangouts, Facebook Messenger etc) are recieving messages even when back ground process stopped manually?

I am trying to implement an Android chat application using web-socket.
I am using an Android service to connect to the web socket server. It is working fine, but when I force stop the service (Not the application) manually in task manager
(Settings -> Apps -> Running)
Then my application is not receiving any messages from server. What I observe from other chat applications is even if I stop the background services of those applications, they are receiving messages and after some time the services also automatically started. How is it possible? Is there any other hidden service that wakes up the main application thread?
You can force start the service every time it is force stopped
Take a look at this (How to automatically restart a service even if user force close it?)
Most of those apps are using a push service such as Google Cloud Messaging.
Continually polling servers or maintaining a persistent web socket is not a resource-friendly method of receiving messages from a server over an extended period of time.
To my knowledge, they do not have a special way of doing this. They may have "work arounds" that are convenient (for example, Facebook Messenger can wake the FB app, if you have both installed and stop only 1 of them).
As of Android 3.1, an app cannot wake itself and GCM also will not wake it. See here: GCM push notifications on android 3.1 : disable broadcast receiver
CommonsWare usually knows what he's talking about. Also, I have tested it and it doesn't work for me on the 3.1+ APIs.

Android: Detecting a Bluetooth device in a background service (Wearable)

I want to create a service for my wearable that runs in background that will detect a Bluetooth device. I have written code that is able to detect the Bluetooth device but it uses Activity - onCreate() method to start scanning.
I read many articles on the internet about writing services that runs in background but in every example the service is started from the Activity. I want my service to be running without starting from any Activity. Is this possible? I mean when I install my app is it possible for the service to start running automatically?
Seems like there is no way of starting a service without starting the Activity. I got the answer from there How to start android service on installation

How can I start service on start up in android? + need some other advice

I'm building an app that collects info about the battery (using background service).
I want this service to start running from the moment I turn on the phone, How do I do it?
On the other hand I want to activate the GUI (interface) of the app only when the user clicks on the app. The app and the background service are in the same project.
Is this the correct way to do what I want?
That is the correct way to do it: see http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html for info about listening for the BOOT_COMPLETED Intent. You can start your Service in the BroadcastReceiver and then bind to it in you Activity.

Categories

Resources