尝试接收bootcomplete或屏幕关闭时,Android的广播接收器不工作 [英] Android broadcast receiver not working when trying to receive bootcomplete or screen off

查看:538
本文介绍了尝试接收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="http://schemas.android.com/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

推荐答案

很好,在屏幕关闭,在屏幕上,这不可能是清单里,但只在运行时。看到这一点:
<一href=\"http://thinkandroid.word$p$pss.com/2010/01/24/handling-screen-off-and-screen-on-intents/\">http://thinkandroid.word$p$pss.com/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: http://thinkandroid.wordpress.com/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的广播接收器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆