receive android device shutdown - android

How receive device shutdown? I mean any broadcast receiver for get device shutdown state.
User press shutdown button on device. Choose shutdown -> Recevier get it.
Any ideas about it?

public static final String ACTION_SHUTDOWN
Since: API Level 4
Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well.
This is a protected intent that can only be sent by the system.
Constant Value: "android.intent.action.ACTION_SHUTDOWN"

Related

Is it possible to call a method before shutdown an android phone?

I want to call a method before shotdown or restart an android phone.
As they said on the official site
Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well.
As of Build.VERSION_CODES#P this broadcast is only sent to receivers registered through Context.registerReceiver.

Android broadcast receiver running always

How do I make a broadcast receiver which runs always, from the very start of the device? Is this possible without starting the application where it is declared?
If not I guess I would have to start my application when the device starts. But this probably adds to much overhead and it's unwanted.
I want this always runnning broadcast receiver in order to listen always for c2dm notifications. These should notify the user that there are new messages in the application.
If you add the BroadcastReceiver to your Manifest with an Intent Filter to listen for a specific intent, the Receiver will be active upon install.
what do you mean "run always" ?
if you need something to be alive for a long time , and from the OS bootup , you need to :
let the app to be installed only on the internal storage (otherwise it won't work).
set the broadcast receiver to listen to the boot intent .
upon receiving the boot intent, start a service and there listen to the intent you wish to listen to.

Track restarts, shuts down, power up and power down

can we get notification if user restarts, shuts down, power up or down the device
Ajay,
The two Broadcast Actions you are most likely interested in are:
ACTION_BOOT_COMPLETED: This is broadcast once, after the system has finished booting.
ACTION_SHUTDOWN: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping).
Please keep in mind to receive ACTION_BOOT_COMPLETE you must have the RECEIVE_BOOT_COMPLETED permission in your AndroidManifest.xml

how to know device is power off

I want to do something when the mobile device is closing, but I don't know what is the method; could you tell me how to detect if mobile device is shutting down?
I know the method about mobile restart android.intent.action.BOOT_COMPLETED, but I cannot find similar power off.
http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN
public static final String
ACTION_SHUTDOWN
Since: API Level 4 Broadcast Action:
Device is shutting down. This is
broadcast when the device is being
shut down (completely turned off, not
sleeping). Once the broadcast is
complete, the final shutdown will
proceed and all unsaved data lost.
Apps will not normally need to handle
this, since the foreground activity
will be paused as well. This is a
protected intent that can only be sent
by the system.
Constant Value:
"android.intent.action.ACTION_SHUTDOWN"
This would appear to be it? I just Googled your command and it was on the Standard Broadcast Actions list. :)

Android -- What happens when device is unlocked?

I am trying to understand the intents that get launched when the device is unlocked.
For eg: Say my activity is running, and I press the power button (screen off, to lock the phone). INTENT.ACTION_SCREEN_OFF is launched. The activity is paused and the screen goes blank.
Now, when I press the power button again (INTENT.SCREEN_ON gets launched), the activity's onResume method is called. But the device is not yet unlocked.
What happens when the device is unlocked? To put it simply, what is the intent's action and category?
Check out ACTION_USER_PRESENT.
Additionally to
ACTION_USER_PRESENT
Broadcast Action: Sent when the user is present after device wakes up
(e.g when the keyguard is gone). (API Lvl 3)
Android SDK 24 added
ACTION_USER_UNLOCKED
Broadcast Action: Sent when the credential-encrypted private storage
has become unlocked for the target user. This is only sent to
registered receivers, not manifest receivers.

Categories

Resources