Witajcie,
w aplikacji ustawiłem sobie notyfikacje. Problem polega na tym, że jak zmienię wersję językową mojej apki (czyli wykonam na aktywności operacje finish()) lub uruchomię ponownie telefon, notyfikacje nie pojawiają się. W jaki sposób ustawić notyfikacje aby to obejść?
Mój dotychczasowy kod (a raczej jego fragmenty odpowiedzialne za wyświetlanie notyfikacji) wygląda następująco:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 48);
calendar.set(Calendar.SECOND, 30);
Intent intent = new Intent(getApplicationContext(), NotoficationReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, pendingIntent);
Klasa NotoficationReceiver:
public class NotoficationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repaetingIntent = new Intent(context, InneAktiwity.class);
repaetingIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, repaetingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.arrow_down_float)
.setContentTitle("Pamiętaj o nauce")
.setContentText("Napisz coś i sie poucz!")
.setAutoCancel(true);
notificationManager.notify(100, builder.build());
}
}
Klasa InneAktiwity:
public class InneAktiwity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nowy_lay);
}
}
Pozdrawiam
Marcin