Is it possible to send Push Notification from the Java server side automatically for the 3rd month between the start date and end date for each other user?

I know this is a simple question, but I'm new here. Can I find out if it is possible to send a push notification from the Google cloud (backend, java server) to devices (Android) every 3 months before the end date. If so, how? and can I initiate a repeated notification during the time interval?

In my Android application (client), I have these classes https://github.com/googlesamples/google-services/tree/master/android/gcm/application/SRC/home/Java/gsm/playback/Android/samples/ com / gcmquickstart

then I made a backend in java and I have these classes:

public class RegisterUserDetails { public String RegisterUserDetails(String data) { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity fdUsers = new Entity("fdUser"); Logger log = Logger.getLogger(RegisterUserDetails.class.getName()); log.setLevel(Level.INFO); JsonElement jsonElement = new JsonParser().parse(data); JsonArray jsonArray = jsonElement.getAsJsonArray(); // JsonObject jsonObject = jsonArray.get(0).getAsJsonObject(); String regId = jsonArray.get(0).getAsString(); String userName = jsonArray.get(1).getAsString(); log.info("regId"+regId); log.info("userName"+userName); fdUsers.setProperty("regId", ""+regId); fdUsers.setProperty("userName", ""+userName); // fdUsers.setProperty("userName", "" + userName); datastore.put(fdUsers); return "Success"; } } 

and I

 import com.google.android.gcm.server.Constants; import com.google.android.gcm.server.Message; import com.google.android.gcm.server.Result; import com.google.android.gcm.server.Sender; import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.ApiNamespace; import java.io.IOException; import java.util.List; import java.util.logging.Logger; import javax.inject.Named; import static com.tiya.accountbook.backend.OfyService.ofy; /** * An endpoint to send messages to devices registered with the backend * <p/> * For more information, see * https://developers.google.com/appengine/docs/java/endpoints/ * <p/> * NOTE: This endpoint does not use any form of authorization or * authentication! If this app is deployed, anyone can access this endpoint! If * you'd like to add authentication, take a look at the documentation. */ @Api( name = "messaging", version = "v1", namespace = @ApiNamespace( ownerDomain = "backend.accountbook.tiya.com", ownerName = "backend.accountbook.tiya.com", packagePath = "" ) ) public class MessagingEndpoint { private static final Logger log = Logger.getLogger(MessagingEndpoint.class.getName()); /** * Api Keys can be obtained from the google cloud console */ private static final String API_KEY = System.getProperty("gcm.api.key"); /** * Send to the first 10 devices (You can modify this to send to any number of devices or a specific device) * * @param message The message to send */ public void sendMessage(@Named("message") String message) throws IOException { if (message == null || message.trim().length() == 0) { log.warning("Not sending message because it is empty"); return; } // crop longer messages if (message.length() > 1000) { message = message.substring(0, 1000) + "[...]"; } Sender sender = new Sender(API_KEY); Message msg = new Message.Builder().addData("message", message).build(); List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(10).list(); for (RegistrationRecord record : records) { Result result = sender.send(msg, record.getRegId(), 5); if (result.getMessageId() != null) { log.info("Message sent to " + record.getRegId()); String canonicalRegId = result.getCanonicalRegistrationId(); if (canonicalRegId != null) { // if the regId changed, we have to update the datastore log.info("Registration Id changed for " + record.getRegId() + " updating to " + canonicalRegId); record.setRegId(canonicalRegId); ofy().save().entity(record).now(); } } else { String error = result.getErrorCodeName(); if (error.equals(Constants.ERROR_NOT_REGISTERED)) { log.warning("Registration Id " + record.getRegId() + " no longer registered with GCM, removing from datastore"); // if the device is no longer registered with Gcm, remove it from the datastore ofy().delete().entity(record).now(); } else { log.warning("Error when sending message : " + error); } } } } } 

what to do?

When the user saves the details of the account, he will save the start date and end date in the Google cloud. I want to send a notification to this user every 3 months from this start date to the end date. As in this case there will be many accounts, it can be from the same user or another. I want to know if this is possible? If so, how ??? -

+6
source share
4 answers

Please use the Quartz Scheduler and schedule a task to run a specific code every month. You can find the tutorial here: http://www.mkyong.com/java/quartz-scheduler-example/

+2
source

If you want to send a specific message to all users every month (for example, in the message of the 1st month of all users), you can use the cron task, which runs every month.

As described here: https://cloud.google.com/appengine/docs/java/config/cron

According to the docs you can say

 2nd,third mon,wed,thu of march 17:00 1st monday of sep,oct,nov 17:00 1 of jan,april,july,oct 00:00 
+1
source

You can see the Azure notification hub. https://azure.microsoft.com/en-in/pricing/details/notification-hubs/

His top sentence supports scheduled push messages. Although it is a bit expensive.

Instead, simple server-side logic can also be written to handle repetition and automatically add a message to the outgoing push message queue. It hardly works for several days.

+1
source

Quartz scheduler is an open source task scheduling library where you can schedule tasks from every second to every year. Crontrigger

Example: create a trigger, create a trigger that fires every half hour between 8:00 and 10:00 on the 5th and 20th day of each month.

 import static org.quartz.TriggerBuilder.*; import static org.quartz.CronScheduleBuilder.*; import static org.quartz.DateBuilder.*: 

create trigger

 trigger = newTrigger() .withIdentity("trigger3", "group1") .withSchedule(cronSchedule("0 0/30 8-9 5,20 * ?")) .forJob("myJob", "group1") .build(); 

simple trigger with start date and end date

 Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(TestJob.class) .withIdentity("cronJob", "testJob") .build(); String startDateStr = "2013-09-27 00:00:00.0"; String endDateStr = "2013-09-31 00:00:00.0"; Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(startDateStr); Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(endDateStr); CronTrigger cronTrigger = newTrigger() .withIdentity("trigger1", "testJob") .startAt(startDate) .withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 * * ?").withMisfireHandlingInstructionDoNothing()) .endAt(endDate) .build(); scheduler.scheduleJob(job, cronTrigger); scheduler.start(); 
+1
source

All Articles