Skip to content

Instantly share code, notes, and snippets.

@javieranton-zz
Created May 12, 2020 20:37
Show Gist options
  • Save javieranton-zz/dbc21c845019dc23643cc31a98fcc238 to your computer and use it in GitHub Desktop.
Save javieranton-zz/dbc21c845019dc23643cc31a98fcc238 to your computer and use it in GitHub Desktop.
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.widget.Toast;
import android.content.Context;
import android.os.Bundle;
public class GroupsJobIntentService extends android.support.v4.app.JobIntentService {
/**
* Unique job ID for this service.
*/
static final int JOB_ID = 1000;
/**
* Convenience method for enqueuing work in to this service.
*/
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, GroupsJobIntentService.class, JOB_ID, work);
}
@Override
protected void onHandleWork(Intent intent) {
try{
Bundle extras = intent.getExtras();
String receiverAction = extras.getString("action");
switch (receiverAction) {
case "markNotifAsRead":
NotificationManager nm = (NotificationManager) GroupsJobIntentService.this.getSystemService(Activity.NOTIFICATION_SERVICE);
nm.cancel(extras.getInt("androidNotifId"));
your.namespace.CN1AndroidApplication.removeNotificationFromPersistedQueue(extras.getString("notifId"), GroupsJobIntentService.this);
your.namespace.CN1AndroidApplication.rest("https://www.yourServer.com/endpoint","POST","{\"notifId\":\""+extras.getString("notifId")+"\"}");
break;
}
}catch(Exception e)
{
your.namespace.CN1AndroidApplication.traceError("JobIntentService onHandleWork exc: "+e.toString());
}
}
final android.os.Handler mHandler = new android.os.Handler();
// Helper for showing tests
void toast(final CharSequence text) {
mHandler.post(new Runnable() {
@Override public void run() {
Toast.makeText(GroupsJobIntentService.this, text, Toast.LENGTH_SHORT).show();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment