Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have asked this same exact question before and here is the code I used:</p> <pre><code>public class BootupReceiver extends BroadcastReceiver { private static final boolean BOOTUP_TRUE = true; private static final String BOOTUP_KEY = "bootup"; @Override public void onReceive(Context context, Intent intent) { if(getBootup(context)) { NotificationManager NotifyM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification Notify = new Notification(R.drawable.n, "NSettings Enabled", System.currentTimeMillis()); Notify.flags |= Notification.FLAG_NO_CLEAR; Notify.flags |= Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); Notify.contentView = contentView; Intent notificationIntent = new Intent(context, Toggles.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notify.contentIntent = contentIntent; int HELO_ID = 00000; NotifyM.notify(HELLO_ID, Notify); } Intent serviceIntent = new Intent(); serviceIntent.setAction("com.leozar100.myapp.NotifyService"); context.startService(serviceIntent); } public static boolean getBootup(Context context){ return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(BOOTUP_KEY, BOOTUP_TRUE); } } </code></pre> <p>The service that I start does nothing I just initiate one because I think it just helps the broadcast receiver work. Also this broadcast receiver is registered in my manifest like so: </p> <pre><code>&lt;receiver android:name=".BootupReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;category android:name="android.intent.category.HOME" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Which starts on bootup requiring the permission <code>android.permission.RECEIVE_BOOT_COMPLETED</code></p> <p>Reference to my question can be found <a href="https://stackoverflow.com/questions/5683959/broadcast-receiver-check-a-checkbox-preference-state-on-bootup-then-send-a-noti">here</a></p> <p>P.S. Welcome to stackoverflow</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload