Newer
Older

Peter Joseph De Jonckheere CESM2014
committed
package com.example.notification;

Peter Joseph De Jonckheere CESM2014
committed
import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import com.example.pharmacy.frontEnd.MainActivity;
import com.example.pharmacy.frontEnd.R;

Peter Joseph De Jonckheere CESM2014
committed
/**
* Created by pharmacy on 09/01/2018.
*/
public class SedentaryNotification implements Notification {

Peter Joseph De Jonckheere CESM2014
committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
private int snId = 0;
public boolean send(Context context) {
buildNotification(context);
return false;
}
private boolean buildNotification(Context context){
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder;
if(Build.VERSION.SDK_INT >= 26){
NotificationChannel nc = createNotificationChannel();
mBuilder = new NotificationCompat.Builder(context, "sednc");
} else {
mBuilder = new NotificationCompat.Builder(context, "sednc");
//Set parameters for non nc Builder here
}
//Up to set Content Intent taken from developers page and must be refined or if works cited.
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, MainActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// mId allows you to update the notification later on.
mNotificationManager.notify(snId, mBuilder.build());

Peter Joseph De Jonckheere CESM2014
committed
return false;
}

Peter Joseph De Jonckheere CESM2014
committed
@TargetApi(26)
private NotificationChannel createNotificationChannel(){
NotificationChannel nc = new NotificationChannel("sednc", "sedentaryNotification", NotificationManager.IMPORTANCE_DEFAULT);
//set parameters of nc dependent on user requiements
return nc;
}

Peter Joseph De Jonckheere CESM2014
committed
public boolean setParameters() {
return false;
}
}