I am trying to develop an Android lock screen app and I completed all features except one.
When the phone has rebooted, it shows the home screen, but I want to show my lock screen app so I added the following broadcast receiver:
<receiver android:enabled="true" android:name="receiver.LockScreenReceiver">
<intent-filter android:priority="999">
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
and in the onreceive() method, I start an activity. When the phone has rebooted, my lock screen app opens after 5-10 seconds later, but I want to show my app when the phone has rebooted.
I cannot find any solution. I saw many lock screen apps and they opens with a maximum of 5-10 seconds delay.
I found an app - Next lock screen. It works. It opens the first time after rebooting the phone.
This can increase you priority but still there would be some delay. Since android first load its OS and the all the other activity starts.
<receiver
android:name="receiver.LockScreenReceiver"
android:enabled="true"
android:exported="true"
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Related
I try to do this for my application to launch automatically when device is rebooted.But this is not working on android 11 devices.
<uses-permissionandroid:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".boot.StartUpBootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
You can't launch an Activity from the background on Android 11. The Receiver is working fine most likely. It's the launching that is no longer allowed by the OS.
If you want to make a kiosk mode app, the correct way to do this is to make this app the launcher app so it takes over the home screen.
Is it possible to detect when a service is stopped or destroyed by one of its own methods? e.g.
onDestroy() (not currently working)
What I need is to detect, from inside the service, whenever the device is rebooted or turned off.
You could create a BroadcastReceiver to listen for the ACTION_SHUTDOWN and QUICKBOOT_POWEROFF intents:
<receiver android:name=".PowerOffReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
Conversely you can listen for the BOOT_COMPLETED intent for when the phone is back on:
<receiver android:name=".PowerOnReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Keep in mind the latter requires the device to be unlocked by the user first. In newer API, you can listen for LOCKED_BOOT_COMPLETED which will allow you to start your service or do whatever you need before the device is unlocked.
I've got an app with the following in the manifest
<receiver android:name="com.redacted.BroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<activity android:name="com.redacted.activity.UserLaunch" android:label="#string/app_name" android:launchMode="standard" android:clearTaskOnLaunch="true" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
If I install and run the app via Android Studio, then reboot the phone then the BroadcastReceiver's onReceive() gets called as a consequence of connectivity changes settling down after boot up.
However if I build an .apk and then install that, then on device reboot the onReceive() is not getting called. (There is a Log.d() statement in the onReceive which I'm looking for in logcat after bootup, it appears with the first installation method but not with the second).
Why is there this difference?
Apps are installed in a so-called "stopped state". It takes an explicit Intent starting up one of the app's components to move out of the stopped state. Usually, that's running the launcher activity. While in the stopped state, no registered broadcast receivers will work.
So, when you run from Android Studio, the launcher activity moves your app out of the stopped state, and all is good. Installation by some other means would require you to run the launcher activity yourself to move out of the stopped state.
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.
I have an app and I want to get notifications. It works fine when my phone is running background. But when I clear memory or restart my phone it is not getting notifications.
My Receiver extends BroadcastReceiver class. And I use this on manifest:
<receiver android:name=".Main$MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.xx.UPDATE_STATUS" />
</intent-filter>
</receiver>
I want to get notifications when my app is running on foreground, background , I mean every time is it possible?