簡體   English   中英

在特定時間設置通知android

[英]Set notification at specific time android

我意識到以前有人問過這個問題,但我對這個問題已經無能為力了。

我有一個警報管理器來設置通知:

public void to_reminder(View view)
{
    Intent intent=new Intent(this,Notification_morning.class);
    AlarmManager manager=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
    PendingIntent pendingIntent=PendingIntent.getService(this,
            0,intent, 0);
    Calendar cal=Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, timepicker.getCurrentHour());
    cal.set(Calendar.MINUTE,timepicker.getCurrentMinute());
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    manager.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),24*60*60*1000,pendingIntent);

}

...然后我的通知本身就是一項服務:

public class Notification_morning extends Service {

    @Override
public void onCreate() 
{   


Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
Intent resultIntent=new Intent(this, Calendar_start.class);
PendingIntent pIntent=PendingIntent.getActivity(this,0,resultIntent,0);


Notification noti_builder= new Notification.Builder(this)
.setContentTitle("Don't forget to plan your activitites for the day! ")
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //what does this do!?


noti_builder.flags |=Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(1,noti_builder); 

}
@Override
    public IBinder onBind(Intent intent) {
    return null;
    }

}

.... 我加入了吐司以確保我真的要使用這種方法。 吐司出現,但通知沒有。 我在這里做錯了什么? 我需要更改清單文件中的內容嗎?

沒有圖標(或者是標題?),通知不起作用。

我確定我之前遇到過同樣的問題,因為通知的一個元素是,如果您省略它,通知將不會顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM