I want track when going inclusion/shutdown(one from two) the telephone.
Probably, I must use BroadcastReceiver. I found action for intent - ACTION_SHUTDOWN.
http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN
But, I am not sure that is will be work when I remove my battery from device. Are there action for inclusion device?
I am not want to use Service...
Related
I'm trying to implement a system level lock screen from a third-party/device-owner MDM app in Android.
I tried looking up on the internet for ways for third-party apps to implement system level lock-screen but from the information that I was able to gather there doesn't seem to be a standard way to implement the same.
The approach we are currently using for the same is to use the (system) overlay permission and showing up the overlay when the boot completes (BOOT_COMPLETED system broadcast intent) and when the device gets locked.
To know when the device gets locked, there were two approaches that we mainly found for the same.
Use a background service, add an invisible overlay, listen to key events until we find a key event related to the power button
Use a background service, register a receiver for SCREEN_OFF event there, and wait for the same.
In both the approaches, we need to use a background service which could potentially drain out battery... By any chance, is there any event/broadcast intent that we could listen to, to make this more efficient overall for the given use case?
I have a series of Android apps, and I need to coordinate their execution. On any given device, there can be any one of those apps installed, or any two of them installed, or any three of them, or any four, and so on. All of those apps can do one specific thing, and they all will try to do that thing from time to time. Now here's the problem: at any instant, at most one of those apps should be allowed to do that thing. If any one app is doing that thing, none of the other apps should be doing it; they should either wait for their turn, or simply pass. In other words, I need a global mutex or critical section mechanism on Android. In addition, I want to avoid NDK, if possible. What should I do?
You might have to give a bit more detail to get a more specific answer. But from what I understand it sounds like you could use BroadcastReceiver in each application that listens for an action to get broadcast and takes it as sign that it needs to either wait, or cancel it's action. Then inside each application whenever you are going to start your action you broadcast an intent with the action string something like `com.your.packagename.ACTION_STARTING_THE_THING. All of the other apps that are installed (if any) will receive this intent and can act upon it accordingly.
I am stuck up with the two actions in the broadcast receiver.
1) ACTION_TIME_CHANGED
2) ACTION_TIME_TICK
Is there any way of determining the fact that the time is changed by the user manually from the device settings and not by the system automatically?
These broadcasts somehow are triggered for automatically as well which I am not looking forth.
Can anyone provide me with any suggestions for the same?
I was looking at the following SO question, but can there be any possible alternative for the same?
Android: is there any additional information from Intent.ACTION_TIME_CHANGED?
I'm a newbie in both Java and Android and I'm trying to figure out how to do the following action. Btw, I find that the official Google Android documentation is NOT for newbies and would like any referral to something a bit more... non-native programmer friendly.
Ok, here goes:
I would like to turn on/off Bluetooth automatically when I plug in/unplug the phone - pc or ac.
So, I have found the following components:
BatteryManager: Seems like using the ACTION_BATTERY_CHANGED intent is the way to go, and setting up a broadcast receiver for when this changes. Is it correct?
I've also found BluetoothAdapter and within that, there's the enable() method. Which says: "do not use without explicit user action to turn on Bluetooth." - is plugging in the phone a explicit user action? Is this the right thing for me to use? The same goes for disable(), of course.
Also, the BroadcastReceivers I've seen examples for in the Internet(s) only show me how to launch an intent - usually to open a new activity. I assume I can have the Broadcast Receiver launch a method in which I will turn bluetooth on and off? Can an intent be a method, and not just activity?
Any help would be appreciated!
BatteryManager: Seems like using the ACTION_BATTERY_CHANGED intent is the way to go, and setting up a broadcast receiver for when this changes. Is it correct?
Yes, that is one way to monitor things like when a charger has been connected (including plugging to a USB port with charge capability). You can also use ACTION_POWER_CONNECTED.
is plugging in the phone a explicit user action?
NO - most definitely not unless you create a pop-up asking for the user's consent. To quote the docs for the enable() method...
Bluetooth should never be enabled without direct user consent. If you want to turn on Bluetooth in order to create a wireless connection, you should use the ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.
When I plug my device to charge, 9 times out of 10 I don't want it to do anything but charge. If I had your app installed on my phone and found out it was enabling Bluetooth silently and without my knowledge, your app would be un-installed straight away.
There are known security issues with Bluetooth and, depending on user settings, you could put somebody's device at risk if it is enabled without their knowledge.
Can an intent be a method, and not just activity?
No, an Intent is part of a messaging system. See Intents and Intent Filters. Yes, I know it's not very 'newbie-friendly' but Android is a complex beast and if you really want to program successfully for it you've got to read this sort of stuff.
I write an android app for athletic examinations in my corporation.
Specifically, in one mile run examination, examiner person needs no interruptions at all, because he will loose 400m checkpoint passes of examinees.
No phone calls, SMS, messages, alarms, calendar notifications, nothing, nothing, nothing.
Until now, I think the easy way: a dialog which informs examiner to go to flight mode. It doesn't cover all these interruptions, but it is the best solution so far.
Is something better out there?
That kind of interruption is simply unavoidable and out of your app reach. Android system receive and emit all kind of interruptions (events) from notification to low battery. Every event has its own app which respond events using intent-filter, broadcast listener, etc. so you can't really have access to all apps that wasn't yours.
Simply put, no you can't. Your Airplane mode solution + No disruption mode might be the best option.
Sounds like you could use the Android Service feature.