Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. public class MyService extends Service
  2. {
  3.  
  4. String dayDifference;
  5.  
  6. NotificationManager manager;
  7. Notification myNotication;
  8.  
  9. @Override
  10. public IBinder onBind(Intent intent)
  11. {
  12. return null;
  13. }//End of onBind method
  14.  
  15. public void onStart(Intent intent, int startId)
  16. {
  17. super.onStart(intent, startId);
  18. manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  19. try {
  20.  
  21. //Dates to compare
  22. String CurrentDate;
  23. String FinalDate= "08/24/2016";
  24.  
  25. Date date1 = new Date();
  26. Date date2;
  27.  
  28. SimpleDateFormat dates = new SimpleDateFormat("mm/dd/yyyy");
  29.  
  30. //Setting dates
  31. date1.setTime(System.currentTimeMillis());
  32. CurrentDate = dates.format(date1);
  33. date2 = dates.parse(FinalDate);
  34. date1 = dates.parse(CurrentDate);
  35.  
  36. //Comparing dates
  37. long difference = Math.abs(date1.getTime() - date2.getTime());
  38. long differenceDates = difference / (24 * 60 * 60 * 1000);
  39.  
  40. //Convert long to String
  41. dayDifference = Long.toString(differenceDates);
  42.  
  43. Log.e("HERE.................", "HERE: " + dayDifference);
  44. System.out.println("..............difference date " + dayDifference);
  45.  
  46. Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  47. Intent targetIntent = new Intent(this, Mnst.class);
  48.  
  49. PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, targetIntent, 0);
  50. NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
  51.  
  52. builder.setAutoCancel(true);
  53. builder.setTicker("Predictor");
  54. builder.setContentTitle("Miisky Notification");
  55.  
  56. builder.setContentText("You have " + dayDifference + " days left. Click on notification to know more..");
  57. builder.setSmallIcon(R.drawable.miilogo);
  58. builder.setSound(soundUri);
  59. builder.setContentIntent(pendingIntent);
  60. builder.setOngoing(true);
  61. //builder.setSubText("Your vault number is " + s.vault_no); //API level 16
  62. builder.setNumber(100);
  63.  
  64. builder.build();
  65.  
  66. //noinspection deprecation
  67. myNotication = builder.getNotification();
  68. builder.setAutoCancel(true);
  69. manager.notify(11, myNotication);
  70.  
  71. Toast.makeText(getApplicationContext(), " "+ dayDifference + " Days Left ", Toast.LENGTH_LONG).show();
  72.  
  73. } catch (Exception exception) {
  74. Log.e("DIDN'T WORK............", "exception " + exception);
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement