Greetings! I'm trying to register an unlock event on the device screen. I hang the receiver with action = "android.intent.action.USER_PRESENT" .
When the application is active, everything works. When I throw the application out of the curtains of the recently launched, it does not work. And this problem is observed with API21 (on 4.4. - everything works). It seems as expected, Google with 21 api is very seriously engaged in optimizing the work of background applications, but somehow this receiver should work?
Manifest code:
<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> </manifest> ScreenReceiver class ScreenReceiver :
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,"unlock screen",Toast.LENGTH_SHORT).show(); } }