Click here to Skip to main content
15,615,448 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I writing 1 app for Android 4.0, and it's started via BroadcastReceiver. My code is below:

In AndroidManifest.xml:
HTML
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name="com.Android.Exercise.StartUpReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <!--<action android:name="StartInstrument" /> 
                <action android:name="PrintControlName" />      -->     
            </intent-filter>
        </receiver>         
        <service android:enabled="true" android:name="StartAUT_Service">
            <intent-filter>
                <action android:name="com.Android.Exercise.StartAUT_Service" />
            </intent-filter>
        </service>  
    </application>


In StartUpReceiver class:

Java
public class StartUpReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i("Broadcast", "onReceive");

        Intent i = null;

        if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
             i = new Intent(context, StartAUT_Service.class);          
             i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        context.startService(i);            
    }       
}


After I rebooted my device, I can not receive broardcast.
Please help me, thank so much
Posted
Updated 13-Mar-12 18:44pm
v3

Take a look at AutoRing Android Service Creation Walkthrough[^] here on CP which uses the reboot startup broadcast.

/Darren
 
Share this answer
 
try like below
In AndroidManifest.xml:
HTML
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:icon="@drawable/icon" android:label="@string/app_name" >
        <receiver android:name="com.Android.Exercise.StartUpReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />

                <category android:name="android.intent.category.DEFAULT" />    
            </intent-filter>
        </receiver>         
        <service android:enabled="true" android:name="StartAUT_Service">
            <intent-filter>
                <action android:name="com.Android.Exercise.StartAUT_Service" />
            </intent-filter>
        </service>  
    </application>


In StartUpReceiver class:

Java
public class BootUpReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
         if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
        Intent i = new Intent(context, StartAUT_Service.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
          }
    }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900