1

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.

Ne0
  • 2,688
  • 3
  • 35
  • 49
  • are you trying to test on HTC device ? – rajpara Sep 13 '12 at 14:49
  • is your .BootReceiver file in com.package path ??? sure ? – Lucifer Sep 13 '12 at 15:01
  • Tired on a HTC device and a Samsung TAB, same results. @Lucifer The .BootReceiver works and has been tested, it doesn't get called if the Main Activity hasn't been run before. – Ne0 Sep 13 '12 at 15:12
  • I am 100% sure, it doesnt require for it, however, you need to remove those comment's from your AndroidManifest.xml to work properly :) – Lucifer Sep 13 '12 at 15:14
  • There is no issue with having comments in the Manifest, but out of curiosity I tried it. Still no `BOOT_COMPLETED` action received. – Ne0 Sep 13 '12 at 15:47

1 Answers1

2

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.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491