Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to build a simple notification in android
    primarykey
    data
    text
    <p>I'm trying to set a notification in my android app that will simply say "It worked", but I need my app to have compatibility all the way down to API 1. I'm really confused on how to do this though. There are old tutorials that are deprecated, and there are new tutorials that don't support older API levels. According to this <a href="https://stackoverflow.com/questions/6391870/how-exactly-to-use-notification-builder">SO</a> question, I should use <a href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html" rel="nofollow noreferrer">NotificationCompat.Builder</a>. There is an example that I'm using, but I don't fully understand the code.</p> <p>Out of this code:</p> <pre><code>Intent notificationIntent = new Intent(ctx, YourClass.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, YOUR_PI_REQ_CODE, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager nm = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); Resources res = ctx.getResources(); Notification.Builder builder = new Notification.Builder(ctx); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.some_img) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img)) .setTicker(res.getString(R.string.your_ticker)) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle(res.getString(R.string.your_notif_title)) .setContentText(res.getString(R.string.your_notif_text)); Notification n = builder.build(); nm.notify(YOUR_NOTIF_ID, n); </code></pre> <p>I get red lines under: <code>ctx</code>, <code>YOUR_PI_REQ_CODE</code>, and <code>YOUR_NOTIF_ID</code></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.
 

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