[英]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.