android - Wakelock not working on Nexus 7 -
hello , in advance , time.
okay problem have developed application shows notification service. had use wakelock in order display notification when screen off.
that works in samsung galaxy s4, running lollipop, don't work in google nexus 7 running jelly bean, when screen off, no notification displayed.
is issue android version? doing wrong or forgetting something?.
can me this?
thank much.
edit: sorry, hadn`t code before. here is...
import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.app.service; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.net.uri; import android.os.handler; import android.os.ibinder; import android.os.powermanager; import android.support.v4.app.notificationcompat; import android.text.format.time; import java.util.timer; import java.util.timertask; public class serviciorecordatorio extends service { public static final long intervalo_notificacion = 60 * 1000; private handler mhandler = new handler(); private timer mtimer = null; powermanager.wakelock wakelock; @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { if (mtimer != null) { mtimer.cancel(); } else { mtimer = new timer(); } mtimer.scheduleatfixedrate(new notificaciontimertask(), 0, intervalo_notificacion); } class notificaciontimertask extends timertask { @override public void run() { mhandler.post(new runnable() { @override public void run() { muestranotificacion(); } }); } private void muestranotificacion() { time today = new time(time.getcurrenttimezone()); today.settonow(); sharedpreferences prefs = getapplicationcontext().getsharedpreferences("com.tonicc.opositest_preferences", context.mode_multi_process); boolean sonido_recordatorio_activado = prefs.getboolean("sonidorecordatorio", false); boolean vibracion_recordatorio_activada = prefs.getboolean("vibracionrecordatorio", false); string[] horaminutos = prefs.getstring("horarecordatorio", "00:00").split(":"); int hora = (integer.parseint(horaminutos[0])); int minutos = (integer.parseint(horaminutos[1])); powermanager powermanager = (powermanager) getsystemservice(power_service); wakelock = powermanager.newwakelock(powermanager.partial_wake_lock, "mywakelocktag"); wakelock.acquire(); if(today.hour == hora && today.minute == minutos) { uri sonido = uri.parse("android.resource://" + getpackagename() + "/" + r.raw.fin_test); int notificacionid = 1; intent = new intent(getapplicationcontext(), bienvenidaactivity.class); i.putextra("notificacionid", notificacionid); pendingintent pendingintent = pendingintent.getactivity(getapplicationcontext(), 0, i, 0); charsequence ticker = getresources().getstring(r.string.ac_servicio_recordatorio_01); charsequence contenttitle = getresources().getstring(r.string.ac_servicio_recordatorio_02); charsequence contenttext = getresources().getstring(r.string.ac_servicio_recordatorio_03); charsequence subtext = getresources().getstring(r.string.ac_servicio_recordatorio_04); notificationcompat.builder noti = new notificationcompat.builder(getapplicationcontext()); noti.setcontentintent(pendingintent); noti.setticker(ticker); noti.setcontenttitle(contenttitle); noti.setcontenttext(contenttext); noti.setsubtext(subtext); noti.setsmallicon(getresources().getidentifier("icono_app_pequeno", "drawable", getpackagename())); noti.addaction(getresources().getidentifier("icono_app_pequeno", "drawable", getpackagename()), ticker, pendingintent); noti.setautocancel(true); if(sonido_recordatorio_activado) { noti.setsound(sonido); } if(vibracion_recordatorio_activada) { noti.setvibrate(new long[]{100, 250, 100, 500}); } notification n = noti.build(); notificationmanager nm = (notificationmanager)getsystemservice(notification_service); nm.notify(notificacionid, n); } wakelock.release(); } } @override public void ondestroy() { super.ondestroy(); mtimer.cancel(); } }
try following wakelock
flags wake screen:
powermanager.wakelock screenon = ((powermanager) getsystemservice(context.power_service)).newwakelock( powermanager.screen_dim_wake_lock | powermanager.acquire_causes_wakeup, tag); screenon.acquire();
this works me on devices.
Comments
Post a Comment