Диспетчер аварийной сигнализации не запускаетAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Диспетчер аварийной сигнализации не запускает

Сообщение Anonymous »

Я новичок в этом, поэтому я немного потерян.

Код: Выделить всё

public class NotificationController{

Context context;

public void createNotification(Context context){

this.context = context;
Notification notification = getNotification();

//creates notification
Intent intent = new Intent(context, NotificationReceiver.class);
intent.putExtra(NotificationReceiver.NOTIFICATION_ID, 1);
intent.putExtra(NotificationReceiver.NOTIFICATION, notification);
PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

//schedules notification to be fired.
AlarmManager  alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 10000 , pIntent);

}

private Notification getNotification(){

Intent intent = new Intent(context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);

Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("Reminder")
.setContentText("Car service due in 2 weeks")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent);
return builder.build();
}
}
< /code>

Мой приемник < /p>

public class NotificationReceiver extends BroadcastReceiver {

public static String NOTIFICATION_ID = "notification-id";
public static String NOTIFICATION = "notification";

public void onReceive(Context context, Intent intent) {

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Notification notification = intent.getParcelableExtra(NOTIFICATION);
int id = intent.getIntExtra(NOTIFICATION_ID, 0);

notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(id, notification);

}
}
Я также зарегистрировался в в AndroidManifest.

Подробнее здесь: https://stackoverflow.com/questions/271 ... triggering
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»