安卓的BroadcastReceiver将无法正常工作

编程入门 行业动态 更新时间:2024-10-09 22:19:26
本文介绍了安卓的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="schemas.android/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 。照片 又见标志 FLAG_INCLUDE_STOPPED_PACKAGES , 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将无法正常工作

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

发布评论

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

>www.elefans.com

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