Important: Please read the Qt Code of Conduct -

Registering Broadcast Receiver on Android

  • Hi, I used this scheme but it seems like the receiver also needs to be registered in order to make it work. (Is that right?)
    The second step I got from here but the callMethod() function cannot find my java function for registration.

    Java.lang.NoSuchMethodError: no non-static method "Lorg/qtproject/qt5/android/bindings/QtActivity;.registerReceiver()V"

    So I tried to call it like this but no luck either.

    Attempt to invoke virtual method 'android.content.Intent android.content.Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)' on a null object reference

    I am kinda out of options. What is the right way to simply create an alarm, receive and raise a notification?
    Thanks and have a nice day!

    Here is the code:

    public class RecieverRegistrator extends QtActivity {
        public void registerReceiver()
            NotificationReceiver nr = new NotificationReceiver();
            IntentFilter intentFilter = new IntentFilter();
            registerReceiver(nr, intentFilter);
    public class SetNotificationAlarm
        public SetNotificationAlarm() {}
        public static void setAlarm(Context context) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 9);
                calendar.set(Calendar.MINUTE, 55);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                Calendar cur = Calendar.getInstance();
                if (cur.after(calendar)) {
                    calendar.add(Calendar.DATE, 1);
                Intent myIntent = new Intent(context, SetNotificationAlarm.class);
                int ALARM1_ID = 10000;
                PendingIntent pendingIntent = PendingIntent.getBroadcast(
                        context, ALARM1_ID, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    Public class NotificationReceiver extends BroadcastReceiver {
    private static NotificationManager m_notificationManager;
    private static Notification.Builder m_builder;
    public void onReceive(Context context, Intent intent) {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        try {
            m_notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                int importance = NotificationManager.IMPORTANCE_DEFAULT;
                NotificationChannel notificationChannel = new NotificationChannel("Qt", "Qt Notifier", importance);
                m_builder = new Notification.Builder(context, notificationChannel.getId());
            } else {
                m_builder = new Notification.Builder(context);
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon))
                    .setContentTitle("A message from Qt!")
        } catch (Exception e) {

    WHAT I CALL FROM main.cpp

    QAndroidJniObject setNotificationAlarm = QAndroidJniObject::fromString("SetNotificationAlarm");


               android:enabled="true" />

  • I found a way to register the receiver here. Not sure how I could miss it. There was another mistake with the Intent and IntentFilter which I solved using simple string as here.
    More more useful links here and here dealing with receiver when you close the app or make the phone sleep.

  • Have u called registerReceiver() method somewhere?

  • @ashajg how to registerReceiver in c++?