安卓的BroadcastReceiver将无法正常工作 [英] Android BroadcastReceiver won't work

查看:109
本文介绍了安卓的BroadcastReceiver将无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题,这是推动我坚果。我创建一个BroadcastReceiver,对舱单申报,但它只是不会运行。我试图使它在设备启动触发。这里的code:

I have a really simple problem which is driving me nuts. I am creating a BroadcastReceiver, declaring it on the manifest but it just wont run. I'm trying to make it trigger on device boot. Here's the code:

package com.vullnetdyla.bcreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("ftw", "It worked");
    }
}

和清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vullnetdyla.bcreceiver"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">

    <receiver android:name="com.vullnetdyla.bcreceiver.Receiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

</application>

推荐答案

你有一些活动哪些用户可以启动?

Do you have some Activity which user can launch?

如果这是不是你的问题!由于Android 3.1之后安装的应用程序(包要更具体)是处于停止状态,不接收任何广播。用户必须在以免手动启动一次,使其工作。 请参见关于停止应用程序启动控制释放部分说明的Andr​​oid 3.1 。照片 又见标志<一href="http://developer.android.com/reference/android/content/Intent.html#FLAG_INCLUDE_STOPPED_PACKAGES"相对=nofollow> FLAG_INCLUDE_STOPPED_PACKAGES ,<一个href="http://developer.android.com/reference/android/content/Intent.html#FLAG_EXCLUDE_STOPPED_PACKAGES"相对=nofollow> FLAG_EXCLUDE_STOPPED_PACKAGES 。

If not this is your problem! Since android 3.1 after installation application (package to be more specific) is in stopped state and doesn't receive ANY broadcast. User have to launch it manually at lest once to make it work. See section "Launch controls on stopped applications" in release notes of Android 3.1.
See also flags FLAG_INCLUDE_STOPPED_PACKAGES, FLAG_EXCLUDE_STOPPED_PACKAGES.

这篇关于安卓的BroadcastReceiver将无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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