Я хочу отобразить уведомление и повторять его каждый период. Я прочитал, как это сделать, и сделал этот код в классе, расширяющем 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);
}
Однако я не знаю, почему у меня есть такие ошибки:
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)
В другом упражнении я думаю, что я должен сделать это:
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);
}
В чем здесь проблема?
Большое спасибо.