2017-10-18 41 views
0

嘗試讓警報管理器使用內部通知時遇到問題。這是爲了給應用的用戶一個特定點的通知。以段落形式通知AlarmManager

我的鬧鐘設置在一個片段內,代碼如下。

 Intent notificationIntent = new Intent(getContext(), DeviceBootReceiver.class); 
     PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

     int hour = Integer.parseInt(vars.getShowRapport().getFinishTime().split(":")[0]); 
     int min = Integer.parseInt(vars.getShowRapport().getFinishTime().split(":")[1]); 

     vars.getShowRapport().getFinishDate().setHours(hour); 
     vars.getShowRapport().getFinishDate().setMinutes(min); 

     long futureInMillis = System.currentTimeMillis()+1000*60; 
     //long futureInMillis = vars.getShowRapport().getFinishDate().getTime(); 
     AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); 
     alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent); 

     getFragmentManager().beginTransaction().replace(R.id.makeRapportFragment,fragment).addToBackStack(null).commit(); 

在我的表現,我有

<receiver android:process=":remote" android:name=".DeviceBootReceiver">/receiver>

最後,在我的接收器,稱爲DeviceBootReceiver我有。

NotificationCompat.Builder builder = 
      new NotificationCompat.Builder(context) 
        .setSmallIcon(R.drawable.ejservicebookincon) 
        .setContentTitle("Rapport finishing") 
        .setContentText("Rapport on item should be done."); 
    Intent notificationIntent = new Intent(context, ServiceRapportMain.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setContentIntent(contentIntent); 
    // Add as notification 
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    manager.notify(0, builder.build()); 

不知道我的問題是,我的接收器似乎從來沒有被激活,所以無法檢查的部分工作作爲尚未。如果有人能指出我的問題在哪裏,請幫助。就像我在Android Studio工作一樣。

+0

:過程=「:遠程「'? –

+0

使用它作爲我遵循的例子使用它,但刪除它沒有做任何事,但確實發現我的錯誤。我使用了AlarmManager.ELAPSED_REALTIME_WAKEUP,然後我應該在這裏使用AlarmManager.RTC_WAKEUP – silvertaildk

回答

0

正如我在上面的評論中寫道,我有錯誤是,我使用AlarmManager.ELAPSED_REALTIME_WAKEUP然後在那裏我應該在這裏你爲什麼要使用`Android的使用是AlarmManager.RTC_WAKEUP