Android Open Source - DailySelfie Alarm Notification Receiver






From Project

Back to project page DailySelfie.

License

The source code is released under:

MIT License

If you think the Android project DailySelfie listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.coursera.dailyselfie;
//from ww w.  j a va  2  s . co m
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class AlarmNotificationReceiver extends BroadcastReceiver {
  // Notification ID to allow for future updates
  private static final int MY_NOTIFICATION_ID = 1;

  // Notification Text Elements
  private final CharSequence tickerText = "Daily Selfie Time";
  private final CharSequence contentTitle = "Daily Selfie";
  private final CharSequence contentText = "Time to take your daily selfie";

  // Notification Action Elements
  private Intent mNotificationIntent;
  private PendingIntent mContentIntent;

  @Override
  public void onReceive(Context context, Intent intent) {

    Log.d("SELFIE", "Alarm Received");
    // The Intent to be used when the user clicks on the Notification View
    mNotificationIntent = new Intent(context, MainActivity.class);

    // The PendingIntent that wraps the underlying Intent
    mContentIntent = PendingIntent.getActivity(context, 0,
        mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

    // Build the Notification
    Notification.Builder notificationBuilder = new Notification.Builder(
        context).setTicker(tickerText)
        .setSmallIcon(android.R.drawable.ic_menu_camera)
        .setAutoCancel(true).setContentTitle(contentTitle)
        .setContentText(contentText).setContentIntent(mContentIntent);
        

    // Get the NotificationManager
    NotificationManager mNotificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);

    // Pass the Notification to the NotificationManager:
    mNotificationManager.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
  }
}




Java Source Code List

com.coursera.dailyselfie.AlarmNotificationReceiver.java
com.coursera.dailyselfie.MainActivity.java
com.coursera.dailyselfie.SelfieViewAdapter.java
com.coursera.dailyselfie.ViewSelfieActivity.java