Android broadcast event of microphone - android

Hello dear Android experts.
I have a simple question: is there any broadcast event I can listen when microphone detects a sound?
Or, if NO (the preambula of the question) is there a way to run ordinary service as long as user need. We have a microphone class which check periodically microphone activity, it runs in service, but Android OS kills it about hour.

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.

Detect when music starts playing (or related events) without polling

My goal is to detect when music starts playing on the device. In my case I want to launch volume controls on an Android Wear device but that's irrelevant for the question.
I know there is AudioManager.isMusicActive() but it requires polling. I would rather listen for a broadcast without keeping a service alive indefinitely.
The other alternative would be to listen for headphones being plugged in but apparently Intent.ACTION_HEADSET_PLUG is only delivered to dynamic receivers as this answer suggests.
I'm a bit clueless here. How can I listen for any audio related events without constant polling?

Service stops automatically in Android

I am working on a Android Project that control Android Device through Speech. For that I am using speech Recognition Service of Google.
Here I have created a service for handling Speech recognition.
But what is going is that after some time this service gets stopped automatically and my device stops responding to the speech of the user.
Then little seconds later, it starts responding again.
So my question here is that how can I stop my service from being destroyed automatically and if possible is there any trick to call my broadcast receiver whenever my service stops?
So that I can create my Broadcast receiver for handling service destruction.
And how can I also stop my device from ringing beep tune when Speak recognition Service going on?
You have to start your Service with startForeground(). You have to pass it a Notification that will be placed in the notification bar permanently. This make your Service unstoppable from the system.
As always refer to android documentation for more details.
http://developer.android.com/guide/components/services.html#Foreground

Android NFC Proof of Concept

I have an idea for an android NFC application but am not entirely sure how to implement it.
I want to be able to have an application that is always on (starts on bootup) and the user cannot exit out of the application. I want two have two phones with NFC enabled. One phone is set up as a listener, the other phone is set up as a sender. Both of these devices will have a code. Sender inputs a code (1234), and the listener has a code (123). If the sender puts the phone up to the listener, and the code is incorrect (1234 instead of 123). The device will lock. The only way the device can unlock is if the sender has the same code as the listener.
I don't want code samples.. I just want an explanation of how you would go about doing this.. and if it is possible.
Basically you need your app to start a service after the phone has booted, use BroadCastReceiver which takes action with the BOOT_COMPLETED intent. When that broadcast receiver has been notified of the boot completion you'll start the service which will handle your nfc jobs.

Categories

Resources