-1

I have to show notification to user at user's selected time and date and my code is below.

public static void setAlarm(Context context, long id, int rYear, int rMonth, int rDay, int rHour, int rMinute) {
    if (Share.wantReminder) {
        Share.wantReminder = false;

        Calendar calendar = new GregorianCalendar(rYear, rMonth, rDay, rHour, rMinute);


        Calendar calendar1 = new GregorianCalendar();
        calendar1.setTimeInMillis(System.currentTimeMillis());
        calendar1.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
        calendar1.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
        calendar1.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH));
        calendar1.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
        calendar1.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));

        Intent intent = new Intent(context, ReminderService.class);
        intent.setAction(String.valueOf(id));
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), pendingIntent);

        Toast.makeText(context, "Alarm set", Toast.LENGTH_SHORT).show();
    }
}

My Manifest.xml

    <receiver android:name=".service.ReminderService">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

No notification are comes to actionbar
What should I do?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

Please share ReminderService.class you must have the notification settings complete to trigger this place.

<receiver android:name=".ReminderService">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

My method is triggered here and it doesn't accept service per

<receiver android:name=".AlarmReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.TIME_SET" />
            <action android:name="android.intent.action.TIMEZONE_CHANGED" />

            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </receiver>
Trk
  • 95
  • 1
  • 12
  • ReminderService,class is fine, no issue at there I have facing that no notification comes While using instant Notification, It works but at specific time , it does not – Harshil kakadiya Oct 05 '18 at 10:48
0

Make below changes to your receiver in Manifest.xml

<receiver
            android:name=".service.ReminderService"
            android:process=":remote"
            android:excludeFromRecents="true" />

Create and display notification inside onReceive() method of ReminderService class as shown below.

public class ReminderService extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent)
    {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
        wl.acquire();

        //Put your code here to create notification

        wl.release();
    }
}

Add below permission in your Manifest.xml

<uses-permission android:name="android.permission.WAKE_LOCK" />