Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android notification after reboot

I want to put up a notification in the notification bar that will launch my app when pressed. While I have no problems doing this, my users want the notification to come up after a reboot as well. They have an app from another vendor that does this.

Everything I can find states that the app must be running for the notification to display. Any ideas?

like image 904
miannelle2 Avatar asked Dec 11 '11 01:12

miannelle2


People also ask

Why are my notifications not showing up on Android?

Cause of Notifications Not Showing up on AndroidDo Not Disturb or Airplane Mode is on. Either system or app notifications are disabled. Power or data settings are preventing apps from retrieving notification alerts. Outdated apps or OS software can cause apps to freeze or crash and not deliver notifications.

Why are my notifications not showing up on my Samsung phone?

To receive notifications as they come, you'll need to make sure that Do Not Disturb is disabled completely. Step 1: Open up the Settings app and navigate to Notifications section. Step 2: Scroll down to select Do not disturb. Then turn off Do not disturb and make sure it isn't scheduled to turn on automatically.


1 Answers

You need to add a receiver that launches a Service after a reboot.

In your manifest register for Boot Complete

<service android:name="com.meCorp.service.MeCorpServiceClass"/>
...
<receiver android:name="com.meCorp.receiver.MyRebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

In your boot receiver, launch a service.

public class MyRebootReceiver extends BroadcastReceiver {

       @Override
       public void onReceive(Context context, Intent intent) {
          Intent serviceIntent = new Intent(context, MeCorpServiceClass.class);
          serviceIntent.putExtra("caller", "RebootReceiver");
          context.startService(serviceIntent);
       }
}

Here is an example for a service class to run in the background.

    public class MeCorpServiceClass extends IntentService{

         @Override
         protected void onHandleIntent(Intent intent){
             String intentType = intent.getExtras().getString("caller");
             if(intentType == null) return;
             if(intentType.Equals("RebootReceiver"))
                  //Do reboot stuff
             //handle other types of callers, like a notification.
         }
     }

OR Just use a third party like Urban AirShip, which handles all that for you.

like image 171
eSniff Avatar answered Oct 10 '22 01:10

eSniff