Search code examples
javaandroidservicebroadcastreceiverautostart

Boot completed is not working after first attempt from adb


I want to receive a BOOT_COMPLETED intent action in order to start a service after boot. It works only after first adb execution (using 'am broadcast -a android.intent.action.BOOT_COMPLETED'). I mean when I restart my phone the receiver does not work. Here are my related parts of code...

AndroidManifest.xml

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/
    <receiver android:name=".AutoStart">
        <category android:name="android.intent.category.DEFAULT" />
        <intent-filter >
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <activity android:name=".Hsap"></activity>
    <service android:enabled="true" android:name=".HsapService"></service>

AutoStart

public class AutoStart extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context arg0, Intent arg1) 
    {
        Log.d("AutoStart","Broudcast received");

        Intent intent = new Intent(arg0,HomasapService.class);
        arg0.startService(intent);
   }
}

Service, On Start:

    @Override
    public void onStart(Intent intent, int startid)
    {

        Log.d("Service","Here");
        serverTask = new ServerTask();
        Thread serverThread = new Thread(serverTask);
        serverThread.start();
    }

Any idea to fix the problem?


Solution

  • I fixed the problem. My application was restricted by startup manager!