简体   繁体   English

在一项服务中重复不同的通知

[英]Repeating different notifications in one service

I'm developing an app that gives a notification at 8 am and 8 pm so what i wanna do is give 2 different notification like at 8 am he say hello it's morning and at 8 pm he say hello it's evening so how can i do that by 1 service and 1 alarm manager.我正在开发一个应用程序,它会在早上 8 点和晚上 8 点发出通知,所以我想做的是发出 2 个不同的通知,比如早上 8 点他打招呼是早上,晚上 8 点他打招呼是晚上,所以我该怎么做由 1 个服务和 1 个警报管理器组成。 Can someone gives me full example for that .有人可以给我完整的例子吗。

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            
    }

}

Now while starting your service just put an extra like this -现在,在启动您的服务时,只需添加这样的额外内容 -

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