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:
Class code:
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();
}}