[英]BroadcastReceiver onReceive is not getting called
我在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>
并将接收者定义如下:
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);
}
}
但是当我解锁屏幕并且没有显示LoginActivity时,不会触发广播接收器。 LoginActivity是android sdk附带的默认loginactivity。
我是否遗漏了使用许可或其他内容,请告诉我。 谢谢
Santhosh
你应该像这样解决问题
i.setClassName("com.example.hello", "com.example.hello.LoginActivity")
你必须拦截的动作是:
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.