广播接收器接收不到ACTION_BOOT_COMPLETED如果应用程序尚未运行? [英] Broadcast Receiver not receiving ACTION_BOOT_COMPLETED if app hasn't been run?

查看:156
本文介绍了广播接收器接收不到ACTION_BOOT_COMPLETED如果应用程序尚未运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力创造一个没有一个活动的应用程序服务,我遇到了一些问题。

我要服务,从开机运行,所以自然使用 BroadcastReciever ACTION_BOOT_COMPLETED 这是没有问题而测试。我用了一个活动来启动和停止服务来测试它正在重新启动,然后看是否启动接收机的工作,它没有,快乐的日子。

删除了测试活动,并从应用程序和使用下面的清单。

 <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.package
安卓版code =1
机器人:=的versionName1.0>
<用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =15/>
<使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>
<应用
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <! - <活动
        机器人:名字=。MainActivity
        机器人:标签=@字符串/ title_activity_main>
        &所述;意图滤光器>
             <作用机器人:名字=android.intent.action.MAIN/>
             <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT; - >
    <接收机器人:名字=。BootReceiver>
        &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
        &所述; /意图滤光器>
    < /接收器>
    <服务机器人:名字=。SWKeepAliveService/>
< /用途>
< /清单>

卸载然后重新安装应用程序,重新启动设备并没有什么。测试了几个时间 -a android.intent.action.BOOT_COMPLETED亚行外壳AM广播,仍然一无所获。

一些试验和错误我想通了广播接收器后从未收到 ACTION_BOOT_COMPLETED 如果应用程序从未运行。当然,没有一个发射器,它永远不会运行。

我错过了什么?我还没有见过这样的任何提及的文件中。

修改1

进行了一些测试,我AOSP版本,上面的清单是在姜饼罚款,但不能在果冻豆。一定有什么变​​化,我只能假设这是出于安全原因(可以理解)。虽然我还没有看到任何文件支持的事实。


解决方案

  

我错过了什么?



  

我还没有见过这样的任何提及的文件中。


这是在了Android 3.1版本文档,<一个HREF =htt​​p://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html相对=nofollow>博客由秃顶的家伙的岗位,一个看似<一个HREF =htt​​p://stackoverflow.com/a/9682814/115145>无限 答案的数量这里在计算器上。

I have been trying to create an app service that does not have an Activity and i ran into some issues.

I want the service to run from boot, so naturally used a BroadcastReciever to catch ACTION_BOOT_COMPLETED this is no problem while testing. I used an Activity to start and stop the service to test it was working then rebooted to see if the boot receiver worked, it did, happy days.

Removed the test Activity and from the application and used the below manifest.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package"
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:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!-- <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />  
        </intent-filter> 
    </activity>  -->
    <receiver android:name=".BootReceiver">
        <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name=".SWKeepAliveService" />
</application>
</manifest>

Uninstalled then reinstalled the application, reboot the device and nothing. Tested it a few time with adb shell am broadcast -a android.intent.action.BOOT_COMPLETED, still nothing.

After some trial and error i figured out the broadcast receiver never receives the ACTION_BOOT_COMPLETED if the application has never run. Of course without a launcher, it would never run.

Have i missed something? I haven't seen any mention of this in the documentation.

EDIT 1

Ran some tests with my AOSP builds, the above manifest is fine on Gingerbread, but NOT on Jelly Bean. Something must have changed, i can only assume it's for security reasons (understandable). Though I haven't seen any documentation to support the fact.

解决方案

Have i missed something?

Yes.

I haven't seen any mention of this in the documentation.

It was mentioned in the Android 3.1 release documentation, blog posts by balding guys, and a seemingly infinite number of answers here on StackOverflow.

这篇关于广播接收器接收不到ACTION_BOOT_COMPLETED如果应用程序尚未运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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