Can't get broadcast in ICS

I am writing 1 application for Android 4.0, and it started through broadcastreceiver. My code is below:

In AndroidManifest.xml:

 <uses-permission android:name="android.permission.INTERNET" />
    <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 the StartUpReceiver class:

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 rebooting my device, I cannot get broardcast. Please help me, thank you very much

+5
source share
3 answers

Starting with Android 3.0, application state has been introduced. All applications are now installed with the state turned on inactive, which makes BroadcastReceivers inactive.

To make the state active, the user must run the application at least once, and the OS automatically activates the application and all its BroadcastReceivers.

, . , .

, , .

: Android ICS sms

, .

, Ahmad

+7

 <uses-permission android:name="android.intent.action.BOOT_COMPLETED" />

+1

, .

If your API level is below 12, then install the following before broadcasting it:

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 32);

Otherwise, add the following flag to enable packages that are also marked as Stopped:

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent. FLAG_INCLUDE_STOPPED_PACKAGES);
0
source

All Articles