Pramish Paudel
Pramish Paudel

Reputation: 11

display notification in specific time of day in android

I am new to android.Can someone show me detail code to make app display notification in certain time of day?

It will be better if you show the code in detail.

I only know to use the local notification.

code is here.

long when = Calendar.getInstance().getTimeInMillis(); when += 10000;

        Intent intent = new Intent(getApplicationContext(),MainActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        long[] pattern = {500,500};

        NotificationCompat.Builder notification =
                (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.notification1)
                        .setContentTitle("My notification")
                        .setContentText("Hello World!")
                        .setContentIntent(pendingIntent)
                        .setLights(Color.BLUE, 500, 500)
                        .setAutoCancel(true)
                        .setVibrate(pattern)
                        .setDefaults(Notification.DEFAULT_SOUND);

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// mId allows you to update the notification later on. mNotificationManager.notify(1, notification.build());

Upvotes: 0

Views: 279

Answers (1)

gipsy
gipsy

Reputation: 3859

Take a look at AlarmManager https://developer.android.com/reference/android/app/AlarmManager.html

AlarmManager allow you to schedule your application to be run at some point in the future

Upvotes: 2

Related Questions