Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private PendingIntent pendingIntent;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, 18);
- calendar.set(Calendar.MINUTE, 40);
- calendar.set(Calendar.SECOND, 0);
- Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
- pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
- AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
- } //end onCreate
- public static NotificationManager mManager;
- @SuppressWarnings("static-access")
- public static void generateNotification(Context context){
- mManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
- Intent intent1 = new Intent(context,MainActivity.class);
- Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());
- intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
- PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context,0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- notification.setLatestEventInfo(context, "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);
- mManager.notify(0, notification);
- }
- @Override
- public IBinder onBind(Intent arg0)
- {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void onCreate()
- {
- // TODO Auto-generated method stub
- super.onCreate();
- }
- @Override
- public void onStart(Intent intent, int startId)
- {
- super.onStart(intent, startId);
- }
- @Override
- public void onDestroy()
- {
- // TODO Auto-generated method stub
- super.onDestroy();
- }
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement