DailyReminder on Java Android

74 views Asked by At

I'm creating a catalogue movie , and now I want to create some notification or anything like this, if user is not opening the app,for a few day or hours,it will show a notification like "Hey Catalogue Movie is missing you",i want the notification is trigger every 7am and then the notification is show , what should i do?,,i already tried to create a notification using JobScheduler,,but its not triggered every 7am

here my code,but this is for get UpcomingMovie

public class GetUpcomingMovies extends JobService {
@Override
public boolean onStartJob(JobParameters params) {
    getUpMovie(params);
    return false;
}

public void getUpMovie(final JobParameters jobParameters){
    Log.d("GetkMovie", "Running");
    AsyncHttpClient client = new AsyncHttpClient();
    String url = "https://api.themoviedb.org/3/movie/upcoming?api_key=*****&language=en-US";
    client.get(url, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            jobFinished(jobParameters, false);
            String result = new String(responseBody);
            Log.d("UpcomingMovie",result);
            try {

                JSONObject responseObject = new JSONObject(result);
                String title = responseObject.getJSONArray("results").getJSONObject(0).getString("title");
                String pesan = "Today";
                String message = pesan+" "+title+" is Released";
                int notifId = 100;
                Log.d("UpcomingMovie",title);
                showNotification(getApplicationContext(), pesan, message, notifId);

            }catch (Exception e){
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            Log.d("GetUpMovie","Failed");
            jobFinished(jobParameters,false);

        }
    });
}

private void showNotification(Context context, String pesan, String message, int notifId){
    NotificationManager notificationManagerCompat = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle("Upcoming Movie")
            .setSmallIcon(R.drawable.ic_notifications_black_24dp)
            .setContentText(message)
            .setColor(ContextCompat.getColor(context, android.R.color.white))
            .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
            .setSound(alarmSound);
    notificationManagerCompat.notify(notifId, builder.build());
}

@Override
public boolean onStopJob(JobParameters params) {
    return false;
}

}

my main activity

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btn_upcom:
        startJob();
            break;
        case  R.id.btn_cancel:
            cancelJob();
            break;

    }

}

private void cancelJob() {
    JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    tm.cancel(jobId);
    Toast.makeText(this, "Job Service canceled", Toast.LENGTH_SHORT).show();
}

 private void startJob() {

    ComponentName mServicecComponent = new ComponentName(this, GetUpcomingMovies.class);
    JobInfo.Builder builder = new JobInfo.Builder(jobId, mServicecComponent);
    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
    builder.setRequiresDeviceIdle(true);
    builder.setPeriodic(180000);
    builder.setRequiresCharging(false);
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(builder.build());
    Toast.makeText(this, "Job Service started", Toast.LENGTH_SHORT).show();

}
0

There are 0 answers