android - Starting JobIntentService from PendingIntent (Notification button)? -
in app, have notification button fires off short network request in background using intentservice. not make sense show gui here, why use service instead of activity. see code below.
// build intent used start notifactionservice intent buttonactionintent = new intent(this, notifactionservice.class); buttonactionintent.setaction(notifactionservice.action_send_confirm); buttonactionintent.putextra(notifactionservice.extra_confirm_id, confirmid); buttonactionintent.putextra(notifactionservice.extra_notif_id, notifid); // build pendingintent used trigger action pendingintent pendingintentconfirm = pendingintent.getservice(this, 0, buttonactionintent, pendingintent.flag_update_current);
this works reliably new background restrictions in android 8.0 made me want move jobintentservice instead. updating service code seems straight forward don't know how launch via pendingintent, notification actions require.
how accomplish this?
would better move normal service , use pendingintent.getforegroundservice(...) on api levels 26+ , current code on api level 25 , below? require me manually handle wakelocks, threads , result in ugly notification on android 8.0+.
how accomplish this?
use broadcastreceiver
, getbroadcast()
pendingintent
, have receiver call jobintentservice
enqueuework()
method onreceive()
method. i'll admit haven't tried this, afaik should work.
Comments
Post a Comment