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 6253573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:01:25+00:00 2026-05-24T14:01:25+00:00

I want to display a notification and repeat it every period. I read how

  • 0

I want to display a notification and repeat it every period. I read how to make that and i maked that code in the class that extends Broadcast Receiver:

public class OnAlarmReceiver extends BroadcastReceiver{
    @Override
     public void onReceive(Context context, Intent intent) {


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

        int icon = R.drawable.icon;
        CharSequence tickerText = "Votre vidange approche";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);


        CharSequence contentTitle = "Notification";
        CharSequence contentText = "Vérifier votre kilométrage";
        Intent notificationIntent = new Intent(this, Acceuil.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

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

        final int HELLO_ID = 1;

        mNotificationManager.notify(HELLO_ID, notification);
     }

However, i don’t know why i have this errors:

The method getSystemService(String) is undefined for the type OnAlarmReceiverThe constructor Intent(OnAlarmReceiver, Class<Acceuil>) is undefined
The method getActivity(Context, int, Intent, int) in the type PendingIntent is not applicable for the arguments (OnAlarmReceiver, int, Intent, int)

In the other activity i guess that i have to do this:

public void notifs() {
        AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent i=new Intent(context, OnAlarmReceiver.class);
        PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);

        mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 1800000, pi);
    }

What’s the problem here ?
Thank you very much.

  • 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-24T14:01:26+00:00Added an answer on May 24, 2026 at 2:01 pm

    The difference is :

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    

    and

    AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    

    The second one works because you call getSystemService on an Application Context, where as in the first you are trying to call it on the this object which at the point is an instance of subclass of BroadcastReceiver which has no method called getSystemService.

    To fix this do :

    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
    
    
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    

    This line gives you problems because you are trying to pass an instance of your custom class as the this object instead of a Context object like it expects.

    To fix this do :

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering how i can make my app display that notification number next
In phone gap iphone application,I want to display local notification at regular interval.So how
I want to display a progress bar while doing some work, but that would
I have a music stream app and I want to display a foreground notification
I want to display compose email in Tab Activity. It is my code. TabHost
I followed the steps here: http://tympanus.net/codrops/2009/10/29/jbar-a-jquery-notification-plugin/ I just want it to display a notification
I'm trying to display a notification using Easy Notification , but I don't want
Essentially i want to display a notification just beneath the UINavigationController, covering the area
I want to display a Visual Notification blinking for the user in my application
i want to display reminder on selected date and time on notification bar of

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.