I am using proximity alerts in one of my applications, however it seems that whenever I reset my phone (via battery pull) or just in general, the proximity alerts are no longer active.
The only way they work once again is if I uncheck and recheck the checkbox (which removes, then re-adds the proximity alert)
Any idea's or reason?
You must reset the alerts. The Android OS does not persist your alerts when rebooting, that's up to your app. Create a BroadcastReceiver (I called mine BootReceiver in my example below) to handle the "android.intent.action.BOOT_COMPLETED" action (this is defined in the manifest). With the BroadcastReceiver you can then restart all of your alerts. Don't forget to add the "android.permission.RECEIVE_BOOT_COMPLETED" permission.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Related
i have been trying to overcome issue of Boot_complete receiver not working in certain devices.
Like Vivo device which have iManager app with auto-start manager.
Where user can toggle app from auto start on device boot.
What should i use along with below as intent-filter to restart my service after device reboot.
Earlier thought of using Battery_Change receiver but it won't work from manifest, as i has to be runtime receiver register.
Any suggestion would be really help-full.
Below is what i have used as intent-filter for my app. In most devices its working as expected. But not in all.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
There is one thing my team and I discovered when facing a similar issue.
You can monitor the usb state like so:
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_STATE" />
</intent-filter>
</receiver>
And if memory serves me right, this will send a broadcast before the regular BOOT_COMPLETED action telling you there is or isn't anything USB connected.
Some manufacturers use their own version of BOOT_COMPLETED as you can read here but the USB_STATE is an alternative, based on the things you want to do. Do note you can get multiple broadcasts using this method!
Alternatively you could look into using an AccessibilityService or the JobService from the firebase sdk. More details here.
I am trying to get a BOOT_COMPLETED receiver to work on a Galays S5 Neo device (running 5.1.1) to start a service right after the device is fully booted.
So in the manifest i defined
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and also added a receiver for the BOOT_COMPLETED intent
<receiver android:name="com.xyzMyApp.BootCompleteReceiver" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
This works fine on nearly all devices no matter if used on battery or not. On the Galaxy S5 Neo this is only working when the device is connected to power on boot. If i use the device on battery and do a reboot, it can take up to 5 minutes until the intent is received.
I also tried to receive other broadcasts like android.net.wifi.RSSI_CHANGED or android.intent.action.USER_PRESENT or android.intent.action.TIME_TICK to maybe use them as a replacement for the boot completed event. The idea was that those events happen pretty often and so after a reboot it won't take very long until one of the receivers is triggered. Turns out that the behavior is the same, on battery it can take up to some minutes until ANY of the receivers receives ANY intent.
I also disabled all kinds of battery optimization for apps i found in the system settings but that did not solve the issue.
Thanks for every hint or idea.
Try to add QUICKBOOT_POWERON as some devices have issues in receiving BOOT_COMPLETED broadcast:
<receiver android:name="com.xyzMyApp.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
Also make sure your app is not installed on external storage(SD card) as suggested on this answer
I am making an android app, in which the app must launch just before the phone is shutting down. Is that possible?
Here i am not talking about encountering phone shutdown event when my app is running.
You will need this permission in your manifest file
<uses-permission android:name="android.permission.DEVICE_POWER" />
And you will listen to the intent like this
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
You can look at the links here for some description and here for official documentation.
I don't know the exact application where you want to use it, but you can have a background service running with the receiver for this intent.
I was expecting my app to load the BroadcastReceiver AutoStartOnBoot when I reboot my device.
I uninstall and install the app. Which means that all existing settings are deleted. I then power down the phone. And power it back up, the Broadcast receiver is never called.
I now, power down the device one more time and power it up again. Yet, broadcast receiver is not called.
I now launch the app once. Clear data. And power it down. I power it up. Now, the broadcast receiver is called.
Manifest
<receiver
android:name=".AutoStartOnBoot"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
I have the permission setup
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Edit:
From your First two Points
1.I uninstall and install the app. Which means that all existing settings are deleted. I then power down the phone. And power it back up, the Broadcast receiver is never called.
2.I now, power down the device one more time and power it up again. Yet, broadcast receiver is not called.
Why it is not working??
Here your just installed the app but not launched.In android after first launch only all your manifest data is registered and all receivers work.But in your third case its working because you are launched the app so here all receivers gets registered.
For more check here Broadcast Receiver not working immediately after package installation
You have to add this permission outside of the <application> tag in manifest file
instead of this
<android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
Add this like
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
The behavior that you describe is perfectly normal. Something needs to use an explicit Intent to start up one of your components before your manifest-registered receivers will work. Typically, that will be the user tapping on your home screen launcher icon.
See the Android 3.1 release notes for more about this.
All answers are correct. This behavior is as per expectation. The app is inactive when installed, until its manually launched by the owner. Only after that is the BOOT_COMPLETED broadcast receiver registered to the OS.
Unless we put the app in the system folder, which keeps all apps in active state. We are device company, adb push your.apk /system/app is possible for us.
Some interesting links, here and here
Could you post a simple code to handle shutdown event.
I need manifest and receiver.
I need the following:
I have a service running in background and I want to detect phone shutting down in order to make it in silent mode so that the terrible operator music doesn't play.
After restarting the phone (I already have on boot receiver) the service will enable phone sound.
You need to listen for the following intent action in your receiver:
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
To make it compatible with some HTC (or other) devices which offer quick power-off feature, you need to include the following action too with in the same intent-filter:
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
For more info, read this
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
public static final String ACTION_SHUTDOWN
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"
And this ACTION_SHUTDOWN may differ from device to device
Like HTC its android.intent.action.QUICKBOOT_POWEROFF