如何创建BroadcastReceiver的无活动/服务? [英] How to create BroadcastReceiver without Activity/Service?

查看:130
本文介绍了如何创建BroadcastReceiver的无活动/服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建的BroadcastReceiver没有活动/服务。虽然我已经没有问题,注册和执行code当一个活动是present在code当我删除失败的活动。

我使用清单(!)但是,当活动从项目中删除它没有被调用。注册的BroadcastReceiver

 <应用
    机器人:allowBackup =真
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <接收器的Andr​​oid版本:NAME =com.ge.test.InstallsListener>
        <意向滤光器>
            <数据机器人:计划=包/>
            <作用机器人:名称=android.intent.action.PACKAGE_ADDED机器人:优先=100/>
        &所述; /意图滤光器>
    < /接收器>
< /用途>
 

感谢。

解决方案
  

但是,当活动从项目中删除它没有被调用。

在Android 3.1及更高版本,用户必须在启动你的活动之一任何明显注册的BroadcastReceiver 将工作。

请参阅了Android 3.1版本说明,特别是关于停止应用程序启动控制一节

I'm trying to create BroadcastReceiver without activity/service. While I've no problem registering and executing the code when an activity is present in the code when I remove the activity it fails.

I do register the BroadcastReceiver using the manifest(!) But it is not being called when the activity is removed from the project.

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name="com.ge.test.InstallsListener" >
        <intent-filter>
            <data android:scheme="package" />
            <action android:name="android.intent.action.PACKAGE_ADDED" android:priority="100"/>                
        </intent-filter>
    </receiver>
</application>

Thanks.

解决方案

But it is not being called when the activity is removed from the project.

On Android 3.1 and higher, the user must launch one of your activities before any manifest-registered BroadcastReceiver will work.

See the Android 3.1 release notes, specifically the "Launch controls on stopped applications" section.

这篇关于如何创建BroadcastReceiver的无活动/服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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