BootReceiver not working in all android devices - android

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.

Related

Is it possible to know when user started using its new android device?

I am working on an app which will be pre-installed in the android device and i want to trigger it in background when end user actually start using its smart phone from the very first time. So is there any broadcast fired for this purpose or any other possible way to do this?
I've used a BroadcastReceiver to accomplish the running something on start, and as for knowing if it's the first time, you could use a shared preference for the app to track it's status of first time or not with a boolean.
Define a BroadcastReceiver the receiver will need the following in the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver
android:name="com.androidfactorem.airwaves.BootAirWaveService"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
You can see a full implementation of a BroadcastReceiver on boot in my git project https://github.com/pbirdsall/airwave

Push notifications are not received when app is not running

At least on a device running Android Jelly Bean (4.2.2) the push notifications are only received if the app is running. I think I'm doing everything right, that is, Im calling Parse.initialize on an Application class (which is referenced on my application tag on the manifest) and I have Parse's PushService and My custom Parse's Push Broadcast Receiver declared on the manifest just like this:
<service android:name="com.parse.PushService" />
<receiver android:name=".ParseCustomPushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.push.intent.RECEIVE" />
<action android:name="com.push.intent.DELETE" />
<action android:name="com.push.intent.OPEN" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
I didnt force quit my app or anything else, for the matter.
I would like my app to always receive push notifications even when is not running, much alike what happens with popular apps such as WhatsApp, Facebook, Skype, etc.
I know I'm not the first one experiencing this problem because I've seen countless posts on several forums of people complaining of Parse push notifications not being received when the app is not running, but none of the answers to those posts offer a workaround...
So, can anyone explain why this even happens?? Is it an Android bug? Is it because Parse's PushService is not sticky? If yes, then, should not it be sticky???
And if possible, please, suggest a workaround for this problem! :)
Thanks!

intent-filter for knowing when some app is being opened?

I would like to know which intent-filter use for listen when some app is being opened from my BroadcastReceiver.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
Android OS doesn't allow this behavior. No broadcast will be sent out when a particular app is opened.
However, you can have a service that is constantly running in the background and in that service you can use the ActivityManager to get a list of the current open apps. Based on that info, you can start your activity. This is a work around.
There is no system broadcast sent out "when some app is being open", for privacy and security reasons.

How to start my application on phone shutdown event

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 am making an app and want to know when the app is uninstalling

I am making an app and want to know when the app is uninstalling. For doing it, I used BroadcastReceiver but I don't know where is my code is wrong? (when my app is uninstalling, BroadcastReceiver can't receive any message about uninstalling)
It's my app's Manifest:
<receiver android:name="receiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.UID_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<data android:scheme="com.example.testpermission"/>
</intent-filter>
You cannot get an event when your own app is uninstalling. See here. There is also a post on the subject here.
You can't, but if you have second installed application on the device - you can get notification via that application about the uninstallation of the first one (as far as I remember).
I believe that the application cannot monitor its own uninstall from two reasons:
It will make it much harder to uninstall application (some evil apps might even try to do something bad when their application is being removed).
If you remove application - you cannot run it, or send it events! The app should be closed for clean deletion.
About how to do it from second app:
Your second app should be a receiver to the ACTION_PACKAGE_REMOVED event (read about BroadcastReceiver, and see: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED)

Categories

Resources