2017-07-31 55 views
0

我正在嘗試做一個簡單的鬧鐘管理器,雖然我添加了5秒的延遲,但是我的手機中的鬧鐘立即熄滅。AlarmManager警報立即熄滅並忽略延遲

我知道,在我的接收器中,報警器現在會關閉, ,但我知道您將延遲設置爲當您希望在未決意圖中關閉時。

我做錯了什麼?

這裏是我的意圖報警:

AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
    Intent intent = new Intent (AlarmClockScreen.this, AlarmNotificationReciever.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); 
    manager.set(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime()+5000,pendingIntent); 

,這裏是我的接收機

public class AlarmNotificationReciever extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 

     builder.setAutoCancel(true) 
       .setDefaults(Notification.DEFAULT_ALL) 
       .setWhen(System.currentTimeMillis()) 
       .setSmallIcon(android.R.mipmap.sym_def_app_icon) 
       .setContentTitle("Alarm TITLE") 
       .setContentText("I will finish, What you started") 
       .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND) 
       .setContentInfo("Info"); 

     NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(1,builder.build()); 

    } 
} 

回答

0

加入

Calendar time = Calendar.getInstance(); 
time.setTimeInMillis(System.currentTimeMillis()); 
time.add(Calendar.SECOND, 30); 
and then using time.getTimeInMillis() 
固定它