Hello!!!
I try to make my app send notifications if isn't used for a day (or more time) but I'm not able to make it. I tried to implement it with code below but not worked. Any idea what I have to add to my code or how to make this possible?
ActivityMain.java
public class MainActivity extends AppCompatActivity {
private static final int NOTIFICATION_REMINDER_DAY = 3;
...
protected void onCreate(Bundle savedInstanceState) {
...
Intent notifyIntent = new Intent(this,NotificationReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast
(context, NOTIFICATION_REMINDER_DAY, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
1000 * 60 * 60 * 24, pendingIntent);
NotificationIntentService.java
protected void onHandleIntent(Intent intent) {
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("D4rK Cleaner!!!");
builder.setContentText("You didn't cleaned your phone for some time. Try now!");
builder.setSmallIcon(R.drawable.ic_splash_screen);
Intent notifyIntent = new Intent(this, MainActivity.class);
@SuppressLint("UnspecifiedImmutableFlag") PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//to be able to launch your activity from the notification
builder.setContentIntent(pendingIntent);
Notification notificationCompat = builder.build();
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(NOTIFICATION_ID, notificationCompat);
NotificationReciver.java
public void onReceive(Context context, Intent intent) {
Intent intent1 = new Intent(context, NotificationIntentService.class);
context.startService(intent1);
Thanks in advance!