Ruchir Baronia Ruchir Baronia - 2 months ago 7
Java Question

Starting my service?

I am having trouble starting my service on boot.



I have a broadcast reciever that should get called whenever the device boots up (it isn't) , and it starts my service. Unfortunately, the service isn't starting!

I have looked at this page, read every answer, and followed every step...but it is still not working. I want to start my service whenever the phone restarts/powers on.




package curlybrace.ruchir.myApp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootUp extends BroadcastReceiver {

private static final String TAG = "myTag";

@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.

Log.v(TAG, "Hooray! Received boot! :) "); //Sadly I am not getting this message

Intent startServiceIntent = new Intent(context, MyService.class);
context.startService(startServiceIntent);



}
}


But my service still wont start. Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="curlybrace.ruchir.myApp"
android:installLocation="internalOnly">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-permission android:name="android.permission.VIBRATE"/>

<uses-permission android:name="android.permission.SEND_SMS"/>


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Settings"
android:label="@string/title_activity_settings"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<service
android:name=".MyService"
android:enabled="true"
android:exported="true" />




<receiver
android:name=".BootUp"
>

<intent-filter>
<action android:name="android.intent.action.RECIEVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>

</receiver>
</application>

</manifest>


I have been stuck on this for the last three days, and I would really appreciate your help. Why is my service not starting on boot?

Answer

Here's how I define my auto start receiver:

<receiver android:name=".receivers.AutoStartReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

Notice the android.intent.action.BOOT_COMPLETED

Comments