簡體   English   中英

在一項服務中重復不同的通知

[英]Repeating different notifications in one service

我正在開發一個應用程序,它會在早上 8 點和晚上 8 點發出通知,所以我想做的是發出 2 個不同的通知,比如早上 8 點他打招呼是早上,晚上 8 點他打招呼是晚上,所以我該怎么做由 1 個服務和 1 個警報管理器組成。 有人可以給我完整的例子嗎。

public class NotifTriggerService extends IntentService {

    public static final String NOTIF_TYPE = "notif_type";

    public static final String NOTIF_TYPE_MORNING = "notif_day";
    public static final String NOTIF_TYPE_NIGHT = "notif_night";


    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     */
    public NotifTriggerService() {
        super("Trigger");
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String notifType = intent.getStringExtra(NOTIF_TYPE);
    if (notifType.equals(NOTIF_TYPE_MORNING)) {
        //Send morning notification
    } else if( notifType.equals(NOTIF_TYPE_NIGHT)) {
        //Send night notification            
    }

}

現在,在啟動您的服務時,只需添加這樣的額外內容 -

Intent intent = new Intent(getActivity(), YourService.class);
intent.putExtra(YourService.NOTIF_TYPE, YourService.NOTIF_TYPE_MORNING);

暫無
暫無

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

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