Permalink
Browse files

Add Details Activity and ContentIntent example

  • Loading branch information...
adamjodlowski committed Jun 19, 2016
1 parent 407bc2d commit 5b7b9795d921ed6618566c70f03a5b3f469a4ce3
@@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailsActivity"></activity>
</application>
</manifest>
@@ -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));
}
}
@@ -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;
@@ -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);
@@ -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.