[英]BroadcastReceiver onReceive is not getting called
I have defined a BroadCastReceiver in AndroidManifest.xml as below 我在AndroidManifest.xml中定义了一个BroadCastReceiver,如下所示
<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 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 broadcastreceiver is not triggered when I unlock the screen and the LoginActivity is not being shown. 但是当我解锁屏幕并且没有显示LoginActivity时,不会触发广播接收器。 LoginActivity is the default loginactivity which comes with android sdk.
LoginActivity是android sdk附带的默认loginactivity。
Am I missing something in uses-permission or something else, please let me know. 我是否遗漏了使用许可或其他内容,请告诉我。 Thanks
谢谢
Santhosh Santhosh
你应该像这样解决问题
i.setClassName("com.example.hello", "com.example.hello.LoginActivity")
The action you have to intercept is: 你必须拦截的动作是:
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
Developer Android ACTION_USER_PRESENT 开发者Android ACTION_USER_PRESENT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.