I have implemented NotificationListenerService in my app. Its Working fine for First time. After sometimes its stop working and onNotificationPosted() never get called. But once i restart the device its start working. But After Sometimes again its Stopped.
I think GC may recycle the Notification service at some stage, and it can be reopen when reboot the device.
This service need to restart device to better working, yes its stoped after while time but if you restart you mobile device and use it without problem :)
Related
I was trying to get to know about the possibilities of getting success of Starting up a forced stop application after the phone reboots. So here is the scenario:
My app will not have any activity. It will be a service only app where no activity will be declared. So my goal is when ever the phone restarts, it will start up the service automatically even though the service is force stopped before the phone reboots. I am using Google Pixel 6 with Android 12 rooted phone. So I have all the necessary permission to achieve the task. I have tried couple of examples from stackoverflow. none of them works. They works only if you keep running the app before the phone reboots. It wont work if the service is Forced stop before the phone restarts. Any help will be appreciated.
I've created a Wear OS app. It has a service running in the foreground. I need to have the app always executing. When I restart the watch the app doesn't start executing again. How can I automatically relaunch the app?
It's my first app for Wear OS and I don't know how to search for this.
Thank you!
I'm not 100% certain, and it's a bad idea for an app to do in most cases. But I believe
https://developer.android.com/reference/android/Manifest.permission#RECEIVE_BOOT_COMPLETED
This will wake up your broadcast receiver so you can run some code, but as you discovered you are probably restricted against starting an activity.
https://developer.android.com/guide/components/activities/background-starts
I am facing an issue with AccessibilityService. When I power off my device AccessibilityService gets unbinded by invoking onUnbind. But when I start my device again, AccessibilityService is not rebinded and onRebind service is not called. I have checked using adb command adb shell dumpsys activity service .MyPackage.AccessibilityService and found my service is alive but is not receiving AccessibilityEvent as service is not rebounded. Everything starts working fine again after I stop and restart my AccessibilityService from settings. How can I fix this issue..? I though about using disableself at onUnbind that because it will force user to start the service from settings, but this call is available from API 24 . So, what should I do..?
I have searched a lot and tried almost everything could be done. Finally I came to a conclusion that this is a android bug, as this problem is not occurring on API 19 or later. For other developers who is suffering from this problem, I suggest you to use preference to store state of your service that it is rebinded or not. Now before you try to use your service check if your service is rebinded or not. If not, tell user that he/she will have to restart the service before using it.
I provided a more detailed answer here. check this out if you are still confused.
I have already red many posts about the subject, some of these works, but only on some devices. For example it works on my Nexus 4, Nexus 5 with cyaogenmod, but not on my Xiaomi Mi2s (jelly beam 4.1.1)
I tried setting it sticky, using alarm, and broadcast receiver on destroy. But neither of them worked out. When I kill the application it never wake up again. But on the same device Whatsapp works perfectly, and even if I kill it, it wake up again..
Is there any way to do it without use GCM?
Some of the link I already looked up:
How to restart a killed service automatically?
Service that repeatedly runs a method, after an amount of time
https://stackoverflow.com/a/21551045/627307
I'm not sure if it will solve the issue for you or not but it worked for me.
I'm running MIUI 6.6.10
Open the Security app provided by Xiaomi
Click on permissions -> Autostart
Here allow your app to auto start
WhatsApp and all famous apps work because Xiaomi white listed them and allowed them to autostart.
some context:
I have an alarm app I use for myself that locks the screen when the alarm goes off for the duration you request prior. Essentially your phone is a ringing brick for x minutes. The only problem is my sleepy self is very irrational and in the morning I figured out that if I turn off the phone and get to the app location and uninstall it before the receiver gets called (boot completed) then I can bypass it bricking my phone. This didn't use to be a big deal when my LG G2 was on 4.2.2 because of how fast the receiver was called I would usually have to restart my phone about 5-8 times to uninstall the app before it was bricked so I just gave up and quit trying. Now, I upgraded to 4.4.2 and the receiver is called about a full 10 seconds later letting me delete the app on the first try every time. Making the app completely useless.
What I have tried:
I have tried using quick_boot in the manifest but I believe that this is only for HTC because on_boot doesn't get called for that OS for some reason. I have also tried the user present which only seems to work after the boot is completed when doing things like unlocking your phone.
Is there really no way to make onReceive be called quicker than onBoot? It would make sense if there isn't , I'm just hoping someone could provide a definite answer either way.
In some cases it is. I'm not 100% sure but i think (some) systemapps have higher priority then the ACTION_BOOT_COMPLETED event. AND there is ACTION_SCREEN_ON which should be triggered before ACTION_BOOT_COMPLETED.
I should have answered this a week or so after I asked this question because I found a pretty useful workaround, although, it is a little sloppy.
I made a new activity(homeLock) with the intent filter . homeLock extends activity and my old main activity(alarmMain) extends homeLock now instead of activity. All homeLock does is start the overlay service(so you can't stop the alarm/use the phone) that will be turned off by alarmMain when it determines whether an alarm should be ringing currently or not. In alarmMain there is a button now that says "change home" which lets you make homeLock the home application. Now, when you turn off the phone and restart to try and delete the application before onBootReceived is called which starts the broadcast receiver(triggers alarm and overlay) the homeLock activity is called which puts an overlay on the screen until it can be removed after the application determines if an alarm should be playing or not (after onBootReceived).
Basically, before you go to sleep just set this application as your home application from within the app or through settings. Now, it should be impossible to delete the application or turn off the alarm once it has started ringing until it has rung its duration because there will always be an overlay on the screen even when restarting the phone.
Obviously this addition is only needed for phones that boot slowly or extremely degenerate sleepers, or both like me. While it is unlikely this will help anyone because it is such a unique problem I thought I should post the workaround I have been using just in case someone does end up finding it useful.