Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyService extends Service
- {
- String dayDifference;
- NotificationManager manager;
- Notification myNotication;
- @Override
- public IBinder onBind(Intent intent)
- {
- return null;
- }//End of onBind method
- public void onStart(Intent intent, int startId)
- {
- super.onStart(intent, startId);
- manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- try {
- //Dates to compare
- String CurrentDate;
- String FinalDate= "08/24/2016";
- Date date1 = new Date();
- Date date2;
- SimpleDateFormat dates = new SimpleDateFormat("mm/dd/yyyy");
- //Setting dates
- date1.setTime(System.currentTimeMillis());
- CurrentDate = dates.format(date1);
- date2 = dates.parse(FinalDate);
- date1 = dates.parse(CurrentDate);
- //Comparing dates
- long difference = Math.abs(date1.getTime() - date2.getTime());
- long differenceDates = difference / (24 * 60 * 60 * 1000);
- //Convert long to String
- dayDifference = Long.toString(differenceDates);
- Log.e("HERE.................", "HERE: " + dayDifference);
- System.out.println("..............difference date " + dayDifference);
- Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- Intent targetIntent = new Intent(this, Mnst.class);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, targetIntent, 0);
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
- builder.setAutoCancel(true);
- builder.setTicker("Predictor");
- builder.setContentTitle("Miisky Notification");
- builder.setContentText("You have " + dayDifference + " days left. Click on notification to know more..");
- builder.setSmallIcon(R.drawable.miilogo);
- builder.setSound(soundUri);
- builder.setContentIntent(pendingIntent);
- builder.setOngoing(true);
- //builder.setSubText("Your vault number is " + s.vault_no); //API level 16
- builder.setNumber(100);
- builder.build();
- //noinspection deprecation
- myNotication = builder.getNotification();
- builder.setAutoCancel(true);
- manager.notify(11, myNotication);
- Toast.makeText(getApplicationContext(), " "+ dayDifference + " Days Left ", Toast.LENGTH_LONG).show();
- } catch (Exception exception) {
- Log.e("DIDN'T WORK............", "exception " + exception);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement