Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:06:23+00:00 2026-05-27T17:06:23+00:00

In My application i am going to use this code to use the Notification:

  • 0

In My application i am going to use this code to use the Notification:

 private void addDefaultNotification(){
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    CharSequence text = "Notification Text";
    CharSequence contentTitle = "Notification Title";
    CharSequence contentText = "Sample notification text.";
    long when = System.currentTimeMillis();

    Intent intent = new Intent(this, NotificationViewer.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Notification notification = new Notification(icon,text,when);

    long[] vibrate = {0,100,200,300};
    notification.vibrate = vibrate;

    notification.ledARGB = Color.RED;
    notification.ledOffMS = 300;
    notification.ledOnMS = 300;

    notification.defaults |= Notification.DEFAULT_LIGHTS;
    //notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);

    notificationManager.notify(com.example.NotifivcationSample.Constants.NOTIFICATION_ID, notification);
}

rightnow i am getting the notofication. By calling that function. But i want is that it should be notify the user even if the application is not runing on at that time on device and notification should be notify on the desired time.

Is it possible ?
If yes then please help me for that.
Thanks.

Edited:

    public class AlarmNotificationReceiver extends BroadcastReceiver{
    //private Intent intent;
    private NotificationManager notificationManager;
    private Notification notification;
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        long value1 = intent.getLongExtra("param1", 0);     
        String value2 = intent.getStringExtra("param2");

        addTwoMonthNotification();

    }
}

I have done like that but not able to create notification in that receiver class. Why ? and what should i have to do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:06:24+00:00Added an answer on May 27, 2026 at 5:06 pm

    Yes it is possible.

    You need to register your intent in AlarmManager and make the notification receiver class to wait for notification from AlarmManager when it’s time to run.

    Basically you will need the following:

    1. Notification Intent class (subclass of Intent)

      public class MyNotificationIntent extends Intent {
          // basic implementation ...
      }
      
    2. NotificationReceiver class, subclass of BroadcastReceiver. Where you receive notification from AlarmManger and need to run your code to show notification (you already have that stuff)

      public class AlarmNotificationReceiver extends BroadcastReceiver{
      
          @Override
          public void onReceive(Context context, Intent intent){
      
              long value1 = intent.getLongExtra("param1", 0);
              String value2 = intent.getStringExtra("param2");
      
              // code to show the notification  
              ... 
              notificationManager.notify(...);
         }
      }
      
    3. Utility function to register your Notification in AlarmManager

      AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      Intent intent = new MyNotificationIntent("com.alex.intent.action.ALARM_NOTIFICATION",
          Uri.parse("notification_alarm_id"), context, AlarmNotificationReceiver.class);
      intent.putExtra("param1", value1);
      intent.putExtra("param2", value2);
      
      PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      alarmManager.set(AlarmManager.RTC_WAKEUP, timeToRun, pendingIntent);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application thats going to use Active Directory for Authentication. This will
Scenarion: I am having a web application which is going to use SqlServerReport(SSRS) sitting
I use asp.net mvc & going to build javascript files at application startup depending
So I'm building an application that is going to do a ton of code
I am going to put an network status icon in my GUI application. To
I have this code will work in multithreaded application. I know that immutable object
In my application i am going to use pushNotification. So in that case how
I was trying to use this library to output text on a OpenGL application
I've got a C# application going that needs to send out an html email
I am designing an application that is going to consist of 3-4 services that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.