Android에서 알람 서비스를 구현하려고합니다.이 서비스는 매일 alarmmanager를 구입합니다. 나는 alarmmanager setRepeating()
의 메소드가 API 18에서 API 19로 변경되었다는 것을 읽었습니다. 이제 setExact()
을 사용해야합니다. 현재 API 18을 구현하고 있습니다. 따라서 영향을받지 않아야합니다. setRepeating()
을 사용하고 처음 알림이 시작될 때 적절한시기에 발생합니다. 그러나 그때 그것은 미쳐 가고 있습니다 : D 알림은 무작위로 계속 해고됩니다. 때로는 3 번, 2 번은 아무것도하지 않습니다.Android 일일 알림 setRepeating 스팸 메일
내 코드 :
private void startAlarm(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.HOUR, 7);
calendar.set(Calendar.AM_PM, Calendar.PM);
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH));
Intent myIntent = new Intent(this , NotifyService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, pendingIntent);
}
내 NotifyService 클래스는 다음과 같습니다 :
public class NotifyService extends Service {
private PendingIntent pendingIntent;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate(){
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(), MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent1, 0);
Notification mNotify = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle(text)
.setContentText(text)
.setSmallIcon(R.drawable.pic)
.setContentIntent(pIntent)
.setSound(sound)
.build();
mNM.notify(1, mNotify);
}
}
관련 수입은 다음과 같습니다
처음 내 응용 프로그램은 다음 줄이 실행됩니다 시작되고있다import android.support.v4.app.NotificationCompat;
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
나는 또한 setExact
을 사용해 보았습니다. i API 19 및 setExact를 호출 할 때마다 알림이 시작되지만 성공하지 못합니다.
아무도 모릅니다.