Запуск службы в определенное время каждый день с помощью alarmanager не работает

Я хочу запускать службу в определенное время каждый день, а затем уведомление о запуске службы каждую минуту, хорошо, что служба работает нормально, но когда ее вызывает диспетчер аварийных сигналов, ничего не происходит.

Здесь код тревоги:

Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());//set the current time and date for this calendar

Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 20);
cal.set(Calendar.MINUTE, 23);
cal.set(Calendar.SECOND, cur_cal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));
Intent intent = new Intent(this, NotifService.class);
PendingIntent pintent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30 * 1000, pintent);

Здесь NotiService.Class:

public class NotifService extends Service {

    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    private static final int HELLO_ID = 1;

    @Override
    public IBinder onBind(Intent arg0) {

        return null;
    }

    @Override
    public void onStart(Intent intent, int startId) {

        super.onStart(intent, startId);
        final Intent intent1 = new Intent(this, DialogoActivity.class);

        scheduler.scheduleWithFixedDelay(new Runnable() {

            @Override
            public void run() {

                // Look up the notification manager server
                NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                // Create your notification
                //int icon = R.drawable.ic_launcher;
                CharSequence tickerText = "Dominion";
                //long when = System.currentTimeMillis();
                //Notification notification = new Notification(icon, tickerText, when);
                Context context = getApplicationContext();
                CharSequence contentTitle = "your turn";
                String contentText = "click here";

                PendingIntent pIntent = PendingIntent.getActivity(NotifService.this, 0, intent1, 0);

                Notification notification = new NotificationCompat.Builder(getApplicationContext()).setContentIntent(pIntent).setTicker(tickerText).setContentTitle(contentTitle).setContentText(contentText).setSmallIcon(R.drawable.ic_launcher).addAction(R.drawable.ic_launcher, "Si", pIntent).setVibrate(new long[] {100, 250, 100, 500}).build();

                notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
                // Send the notification

                nm.notify(HELLO_ID, notification);
            }
        }, 1, 1, TimeUnit.MINUTES);
    }

    @Override
    public void onDestroy() {

        super.onDestroy();
    }
}

person user2964637    schedule 24.11.2014    source источник
comment
приемник вещания на самом деле вызывает его?   -  person Elltz    schedule 24.11.2014
comment
вам может потребоваться вызвать ожидающее намерение из службы, а не из широковещательной рассылки SEE PendingIntent.getService (контекст, код запроса, намерение, флаги)   -  person moh.sukhni    schedule 24.11.2014
comment
я пробую этот PendingIntent.getService(контекст, requestCode, намерение, флаги), но ничего не ошибка, но тоже не работает   -  person user2964637    schedule 25.11.2014


Ответы (1)


Возможно, у вас нет службы, объявленной в Manifest.XML?

См.: Android, моя служба не запускается

person Scott    schedule 19.01.2015