Guest User

Untitled

a guest
Nov 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
  2. pendingIntent = PendingIntent.getBroadcast(getContext(),
  3. 0, alarmIntent, 0);
  4.  
  5. public void setALARM(String time, String strDate){
  6.  
  7. AlarmManager manager = (AlarmManager) getContext()
  8. .getSystemService(Context.ALARM_SERVICE);
  9.  
  10. String strHour=formateDateFromstring("HH:mm","HH",time);
  11. String strMin=formateDateFromstring("HH:mm","mm",time);
  12. String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
  13. String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
  14. String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
  15.  
  16. int hour=Integer.parseInt(strHour);
  17. int min=Integer.parseInt(strMin);
  18. int date=Integer.parseInt(strdate);
  19. int month=Integer.parseInt(strMonth)-1;
  20. int year=Integer.parseInt(strYear);
  21.  
  22. Calendar cal = Calendar.getInstance();
  23. cal.set(Calendar.DAY_OF_MONTH,date); //1-31
  24. cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
  25. cal.set(Calendar.YEAR,year);//year...
  26.  
  27. cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
  28. cal.set(Calendar.MINUTE,min);//MIN
  29. cal.set(Calendar.SECOND,0);
  30.  
  31.  
  32. manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
  33. pendingIntent);
  34. }
  35.  
  36. public class ServiceReceiver extends BroadcastReceiver {
  37.  
  38. @Override
  39. public void onReceive(Context context, Intent intent) {
  40.  
  41. NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
  42. .setSmallIcon(R.drawable.logob_icon_prestigesalon)
  43. .setContentTitle("ABC")
  44. .setContentText("time to go")
  45. .setPriority(NotificationCompat.PRIORITY_DEFAULT);
  46.  
  47. Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
  48.  
  49. NotificationManager notificationmanager = (NotificationManager) context
  50. .getSystemService(Context.NOTIFICATION_SERVICE);
  51. notificationmanager.notify(0, builder.build());
  52. }
  53. }
  54.  
  55. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  56.  
  57. <receiver android:name=".ServiceReceiver">
  58. <intent-filter>
  59. <action android:name="android.intent.action.BOOT_COMPLETED"/>
  60. </intent-filter>
  61. </receiver>
  62.  
  63. <!-- Will not be called unless the application explicitly enables it -->
  64. <receiver android:name=".DeviceBootReceiver"
  65. android:enabled="false">
  66. <intent-filter>
  67. <action android:name="android.intent.action.BOOT_COMPLETED"/>
  68. </intent-filter>
  69. </receiver>
Add Comment
Please, Sign In to add comment