尝试接收bootcomplete或屏幕关闭时,Android的广播接收器不工作

编程入门 行业动态 更新时间:2024-10-12 01:23:25
本文介绍了尝试接收bootcomplete或屏幕关闭时,Android的广播接收器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我想开发一个自定义锁屏

So I am trying to develop a custom lockscreen

但我的广播接收器,将不会触发

but my broadcastreceiver won't fire

我的清单:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="schemas.android/apk/res/android" package="org.alexander.fuchs.lockscreen" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".app" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".myreceiver"> <intent-filter> <action android:name="android.intent.action.SCREEN_OFF"/> <action android:name="android.intent.action.SCREEN_ON"/> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> </application> </manifest>

我的接收器:

public class myreceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("receiver","works"); Toast.makeText(context,"works",Toast.LENGTH_LONG).show(); Intent in=new Intent(context,app.class); context.startActivity(in); } }

接收者应该告诉我,它被激发:D但是疗法不在logcat的任何日志

the receiver should show me that it is fired :D but ther aren't any logs in logcat

推荐答案

很好,在屏幕关闭,在屏幕上,这不可能是清单里,但只在运行时。看到这一点:thinkandroid.word$p$pss/2010/01/24/handling-screen-off-and-screen-on-intents/

well , for the screen off and screen on , this cannot be inside the manifest , but only at runtime . see this: thinkandroid.wordpress/2010/01/24/handling-screen-off-and-screen-on-intents/

在启动时,它必须在清单中,所以别的东西是错的it.check类的路径。这肯定是问题的原因。

for the bootup , it must be in the manifest , so something else is wrong with it.check the path of the class. this is surely the cause of the problem.

更多推荐

尝试接收bootcomplete或屏幕关闭时,Android的广播接收器不工作

本文发布于:2023-11-27 12:56:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接收器   屏幕   工作   bootcomplete   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!