Skip to content

Commit

Permalink
Add Details Activity and ContentIntent example
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjodlowski committed Jun 19, 2016
1 parent 407bc2d commit 5b7b979
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailsActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.adamjodlowski.notifications;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class DetailsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);

Log.d("PLAYGROUND", "Details ID: " + getIntent().getIntExtra("EXTRA_DETAILS_ID", -1));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.adamjodlowski.notifications;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -24,12 +26,25 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View view) {

// Create PendingIntent to take us to DetailsActivity
// as a result of notification action
Intent detailsIntent = new Intent(MainActivity.this, DetailsActivity.class);
detailsIntent.putExtra("EXTRA_DETAILS_ID", 42);
PendingIntent detailsPendingIntent = PendingIntent.getActivity(
MainActivity.this,
0,
detailsIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);

// NotificationCompat Builder takes care of backwards compatibility and
// provides clean API to create rich notifications
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Notification title")
.setContentText("Content text");
.setContentTitle("Something important happened")
.setContentText("See the details")
.setContentIntent(detailsPendingIntent)
.setAutoCancel(true);

// Obtain NotificationManager system service in order to show the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.adamjodlowski.notifications.DetailsActivity">

</android.support.constraint.ConstraintLayout>

0 comments on commit 5b7b979

Please sign in to comment.