android - TTS does not work while device is sleep -


i made program monitors acceleration sensor , says when value measured using tts in service. works fine when device on, when goes sleep works correctly, works after while, works press power button wake device , not works @ all. there idea?

public class myservice extends service implements sensoreventlistener, oninitlistener {      private sensormanager senman;     private sensor accsen;     private texttospeech mtts = null;     private powermanager pm;     private wakelock wl;      @override     public ibinder onbind(intent arg0) {         return null;     }      @override     public void oncreate() {         super.oncreate();         senman = (sensormanager) getsystemservice(context.sensor_service);         accsen = senman.getdefaultsensor(sensor.type_accelerometer);         senman.registerlistener(this, accsen, sensormanager.sensor_delay_normal);         pm = (powermanager)getsystemservice(power_service);         wl = pm.newwakelock(powermanager.partial_wake_lock, "tag");     }      @override     public void ondestroy() {         senman.unregisterlistener(this);         super.ondestroy();     }      @override     public final void onaccuracychanged(sensor sensor, int accuracy) {}      @override     public final void onsensorchanged(sensorevent event) {         double = math.sqrt(math.pow(event.values[0], 2) + math.pow(event.values[1], 2) + math.pow(event.values[2], 2));         if (math.abs(a - 9.8) / 0.98 > 25) say();     }      private void say() {         wl.acquire();         mtts = new texttospeech(this, this);             }      @override     public void oninit(int status) {         if (status == texttospeech.success)             mtts.speak("text say", texttospeech.queue_flush, null);         wl.release();     } } 

tts not work when device asleep. tts not work when device powered off, has had battery removed, or has been smashed bits sledgehammer. tts will work when device awake, either because wake power button, or else wakes device (e.g., alarmmanager, incoming phone call).

sensors may or may not work when device asleep, depending on os version , device manufacturer.

hence, either going need use wakelock keep device awake (at significant battery cost), or going have come app idea.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -