Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com 00004 notifications #4

Merged
merged 6 commits into from
May 6, 2020
Merged

Com 00004 notifications #4

merged 6 commits into from
May 6, 2020

Conversation

AnelCC
Copy link
Owner

@AnelCC AnelCC commented May 5, 2020

04 notifications

A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app. Users can tap the notification to open your app or take an action directly from the notification.

  • Displays outside of you normal app user interface.
  • Trigger specific parts of your application when tapped.
  • Take various forms depending on their information.
  • Can have individual action item associated.
  • Can appear on the user's lock screen.

2. Added Simple notifications icon, text and large icon.

Set the three required items all notifications must have
Set the large icon to be our app's launcher icon
Set the notification to cancel when the user taps on it
Build the finished notification and then display it to the user.

val builder = NotificationCompat.Builder(this, NOTIFY_CHANNEL)
builder.setSmallIcon(R.drawable.ic_notifications_accent)
builder.setContentTitle("Sample Notification")
builder.setContentText("This is a sample notification")
builder.setAutoCancel(true)
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.user_woman_icon))
val notification = builder.build()
val mgr = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
mgr.notify(NOTIFY_ID, notification)

04_simple_notification

2. Added Expanded notifications

Add an expanded layout to the notification

val bigTextStyle = NotificationCompat.BigTextStyle()
bigTextStyle.setBigContentTitle("This is a Expand Notification")
bigTextStyle.bigText(resources.getString(R.string.long_msg))
builder.setStyle(bigTextStyle)

04_expand_notification 04_expanded_notification

3. Add Action Notification.

Create the intent that will start the ResultActivity when the user
taps the notification or chooses an action button
Store the notification ID so we can cancel it later in the ResultActivity

val builder = NotificationCompat.Builder(this, NOTIFY_CHANNEL)
val intent = Intent(this, NotificationResultActivity::class.java)
intent.putExtra("notifyID", NOTIFY_ID)
val pendingIntent = PendingIntent.getActivity(this, NOTIFY_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT)

04_action_notification 04_actioned_notification

4. Display Notification Status on lock screen.

Set the lock screen visibility of the notification

builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)

04_lock_screen

More info here
More info here

@AnelCC AnelCC merged commit 31685d8 into master May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant