Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The evolution of Android notification

The evolution of Android notification

Slides from my talk at Android Makers 2017 about notifications

Jeremie Martinez

April 11, 2017
Tweet

More Decks by Jeremie Martinez

Other Decks in Technology

Transcript

  1. “A notification is a message you can display to the

    user outside of your application's normal UI. […] Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.” Definition
  2. “A notification is a message you can display to the

    user outside of your application's normal UI. […] Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.” Definition
  3. 1

  4. if (BuildUtils.hasMarshmallow()) { alarmManager.setExactAndAllowWhileIdle(type, millis, operation); } else if (BuildUtils.hasKitKat())

    { alarmManager.setExact(type, millis, operation); } else { alarmManager.set(type, millis, operation); } setExact
  5. if (BuildUtils.hasMarshmallow()) { alarmManager.setExactAndAllowWhileIdle(type, millis, operation); } else if (BuildUtils.hasKitKat())

    { alarmManager.setExact(type, millis, operation); } else { alarmManager.set(type, millis, operation); } setExact
  6. if (BuildUtils.hasMarshmallow()) { alarmManager.setExactAndAllowWhileIdle(type, millis, operation); } else if (BuildUtils.hasKitKat())

    { alarmManager.setExact(type, millis, operation); } else { alarmManager.set(type, millis, operation); } setExact
  7. if (BuildUtils.hasMarshmallow()) { alarmManager.setExactAndAllowWhileIdle(type, millis, operation); } else if (BuildUtils.hasKitKat())

    { alarmManager.setExact(type, millis, operation); } else { alarmManager.set(type, millis, operation); } setExact
  8. operation public static PendingIntent getBroadcast( … ) public static PendingIntent

    getActivity( … ) public static PendingIntent getService( … ) PendingIntent
  9. PendingIntent.getActivity( context, 123, intent, FLAG_UPDATE_CURRENT); final Intent intent = new

    Intent(this, MainActivity.class); PendingIntent.getActivity( context, 123, intent, FLAG_UPDATE_CURRENT); = ?
  10. PendingIntent.getActivity( context, 123, intent, FLAG_UPDATE_CURRENT); final Intent intent = new

    Intent(this, MainActivity.class); PendingIntent.getActivity( context, 123, intent, FLAG_UPDATE_CURRENT);
  11. PendingIntent.getActivity( context, 1234, intent, FLAG_UPDATE_CURRENT); final Intent intent = new

    Intent(this, MainActivity.class); PendingIntent.getActivity( context, 1235, intent, FLAG_UPDATE_CURRENT); = ?
  12. PendingIntent.getActivity( context, 1234, intent, FLAG_UPDATE_CURRENT); final Intent intent = new

    Intent(this, MainActivity.class); PendingIntent.getActivity( context, 1235, intent, FLAG_UPDATE_CURRENT);
  13. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); final Intent intent1 = new

    Intent(this, MainActivity.class); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT); = ? final Intent intent2 = new Intent(this, MainActivity.class);
  14. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT);

    final Intent intent1 = new Intent(this, MainActivity.class); final Intent intent2 = new Intent(this, MainActivity.class);
  15. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); final Intent intent1 = new

    Intent(this, MainActivity.class). putExtra("extra1", "extra1"); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT); = ? final Intent intent2 = new Intent(this, MainActivity.class). putExtra(“extra2", "extra2");
  16. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); final Intent intent1 = new

    Intent(this, MainActivity.class). putExtra("extra1", "extra1"); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT); final Intent intent2 = new Intent(this, MainActivity.class). putExtra(“extra2", "extra2");
  17. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); final Intent intent1 = new

    Intent(this, MainActivity.class). addCategory(Intent.CATEGORY_APP_BROWSER); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT); = ? final Intent intent2 = new Intent(this, MainActivity.class). addCategory(Intent.CATEGORY_APP_CALCULATOR);
  18. PendingIntent.getActivity( context, 123, intent1, FLAG_UPDATE_CURRENT); final Intent intent1 = new

    Intent(this, MainActivity.class). addCategory(Intent.CATEGORY_APP_BROWSER); PendingIntent.getActivity( context, 123, intent2, FLAG_UPDATE_CURRENT); final Intent intent2 = new Intent(this, MainActivity.class). addCategory(Intent.CATEGORY_APP_CALCULATOR);
  19. public boolean filterEquals(Intent other) { if (other == null) {

    return false; } if (!Objects.equals(this.mAction, other.mAction)) return false; if (!Objects.equals(this.mData, other.mData)) return false; if (!Objects.equals(this.mType, other.mType)) return false; if (!Objects.equals(this.mPackage, other.mPackage)) return false; if (!Objects.equals(this.mComponent, other.mComponent)) return false; if (!Objects.equals(this.mCategories, other.mCategories)) return false; return true; }
  20. - Use extensively group - Be careful about marketing abuse

    - Don’t forget to remove notifications
  21. SpannableString delayedSpanned = new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(),

    // Spanned.SPAN_INCLUSIVE_INCLUSIVE); delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  22. SpannableString delayedSpanned = new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(),

    // Spanned.SPAN_INCLUSIVE_INCLUSIVE); delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  23. SpannableString delayedSpanned = new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(),

    // Spanned.SPAN_INCLUSIVE_INCLUSIVE); delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  24. delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); SpannableString delayedSpanned =

    new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(getString(R.string.travelTextWithDelay, // time, // delayedSpanned));
  25. delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); SpannableString delayedSpanned =

    new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(getString(R.string.travelTextWithDelay, // time, // delayedSpanned));
  26. delayedSpanned.setSpan(new ForegroundColorSpan(textColor), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); SpannableString delayedSpanned =

    new SpannableString(delayed); delayedSpanned.setSpan(new StrikethroughSpan(), // 0, delayedSpanned.length(), // Spanned.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(TagFormatter.from(this, R.string.travelTextWithDelay). with("arrival_time", time). with("estimated_arrival_time", delayedSpanned). format()); textView.setText(getString(R.string.travelTextWithDelay, // time, // delayedSpanned));