BroadcastReceiver onReceive does not receive a call

I defined BroadCastReceiver in AndroidManifest.xml as below

<receiver android:name="com.example.hello.ScreenUnlockReceiver" android:enabled="true" android:singleUser="true"> <intent-filter> <action android:name="android.content.Intent.ACTION_USER_PRESENT" /> </intent-filter> </receiver> 

and defined the receiver as shown below:

 public class ScreenUnlockReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //start activity Intent i = new Intent(); i.setClassName("com.example.hello", "LoginActivity"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } 

But the transmitter broadcast does not start when I unlock the screen, and the LoginActivity function is not displayed. LoginActivity is the default login feature that comes with sdk for Android.

I missed something in use - permission or something else, please let me know. Thanks

Santhosh

+4
source share
2 answers

The action you must intercept is as follows:

 <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> 

Android Developer ACTION_USER_PRESENT

+4
source

your should fix a problem like this
i.setClassName("com.example.hello", "com.example.hello.LoginActivity")

+4
source

Source: https://habr.com/ru/post/1478965/


All Articles