• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps BroadcastReceiver “action.USER_PRESENT” is not called

I'm trying to register the device unlock event. I use the receiver with action = "android.intent.action.USER_PRESENT".

When the application is active - everything works. When I delete an application from the curtain of recently launched - does not work. And this problem is noticeable with API21 (on 4.4. - everything works). This is expected, because Google from API21 seriously engaged in optimizing the work of background applications, but how does this receiver work? Code of manifest:
HTML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appdroid.develop.receiverscreenlock">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".ScreenReceiver">
        <intent-filter android:priority="2147483647">
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
</application>

Class code:

Java:
public class ScreenReceiver extends BroadcastReceiver {

private static final String TAG = "myLog";

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG,"onReceive "+ intent.getAction());
    Toast.makeText(context,"screen unlock",Toast.LENGTH_SHORT).show();
}}
 
  • Like
Reactions: sweetndreemy73

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones