广播接收器不工作 [英] BroadcastReceiver doesn't work

查看:146
本文介绍了广播接收器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在明显增加接收器

<receiver android:name=".PackageReceiver"
        android:enabled="true">
        <intent-filter android:priority="100">
            <action android:name="android.intent.action.PACKAGE_ADDED"/>
            <action android:name="android.intent.action.PACKAGE_REPLACED"/>
            <data android:scheme="package"/>
        </intent-filter>  
</receiver>

这是我的BroadcastReceiver

And this is my BroadcastReceiver

public class PackageReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {

    Log.e("noti", "sucess");
    //Start Notification Service
    Intent i = new Intent(context, NotificationService.class);
    context.startService(i);
}}

..

当我安装这个包,它没有工作......

When I install this package, It's didn't work...

这包不具有活性。(仅服务和资源)

This package don't have activity.(only service and resource)

这是一个问题吗?

然后..

如何在没有活动的BroadcastReceiver调用这个包?

How to call BroadcastReceiver in this package without activity?

推荐答案

这是问了很多的问题。

看看这个 Commonsware 博客

Check out this Commonsware blog.

3.1时开始安装应用它们是处于停止状态,这样,他们将无法运行,直到用户明确地启动它们。 pressing强制停止将其返回到这个状态。

有需要在应用程序中的活性成分,该用户可以开始。当你的活动得到启动,你的广播接收器将被注册。

There needs to be an active component in your application that the user can start. When your activity gets started, your BroadcastReceiver will be registered.

这篇关于广播接收器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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