[:en]
package com.example.cambridge.notification;
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.support.v4.app.NotificationCompat;
public class AlertReceiver extends BroadcastReceiver{
// Called when a broadcast is made targeting this class
@Override
public void onReceive(Context context, Intent intent) {
createNotification(context, "Times Up", "10 Seconds Has Passed", "Alert");
}
public void createNotification(Context context, String msg, String msgText, String msgAlert){
// Define an Intent and an action to perform with it by another application
PendingIntent notificIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
// Builds a notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ntt_logo_24_24)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
// Defines the Intent to fire when the notification is clicked
mBuilder.setContentIntent(notificIntent);
// Set the default notification option
// DEFAULT_SOUND : Make sound
// DEFAULT_VIBRATE : Vibrate
// DEFAULT_LIGHTS : Use the default light notification
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
// Auto cancels the notification when clicked on in the task bar
mBuilder.setAutoCancel(true);
// Gets a NotificationManager which is used to notify the user of the background event
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Post the notification
mNotificationManager.notify(1, mBuilder.build());
}
}
package com.example.cambridge.notification;
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.support.v4.app.NotificationCompat;
public class AlertReceiver extends BroadcastReceiver{
// Called when a broadcast is made targeting this class
@Override
public void onReceive(Context context, Intent intent) {
createNotification(context, "Times Up", "10 Seconds Has Passed", "Alert");
}
public void createNotification(Context context, String msg, String msgText, String msgAlert){
// Define an Intent and an action to perform with it by another application
PendingIntent notificIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
// Builds a notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ntt_logo_24_24)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
// Defines the Intent to fire when the notification is clicked
mBuilder.setContentIntent(notificIntent);
// Set the default notification option
// DEFAULT_SOUND : Make sound
// DEFAULT_VIBRATE : Vibrate
// DEFAULT_LIGHTS : Use the default light notification
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
// Auto cancels the notification when clicked on in the task bar
mBuilder.setAutoCancel(true);
// Gets a NotificationManager which is used to notify the user of the background event
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Post the notification
mNotificationManager.notify(1, mBuilder.build());
}
}
package com.example.cambridge.notification;
import android.app.Activity;
import android.os.Bundle;
// Called when the notification is clicked on in the task bar
public class MoreInfoNotification extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.more_info_notific);
}
}
// Step 1 // Step 2
[:]
