Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

text to speech - Android call TTS in BroadcastReceiver -


i need call tts service within subclass of broadcastreceiver. when implement class oninitlistener, gave run-time error.

is there other-way implement tts within broadcastreceiver?

thank you,

sorry code:

public class textapp extends broadcastreceiver implements oninitlistener { private texttospeech tts; private string message = "hello";   @override public void onreceive(context context, intent intent) {     tts = new texttospeech(context, this);     message = "hello tts"; }  @override public void oninit(int status) {     if (status == texttospeech.success)     {         tts.speak(message, texttospeech.queue_flush, null);     }   } } 

your code didn't work on :

tts = new texttospeech(context, this); 

context on broadcastreceiver "restricted context". means cannot start service on context in broadcastreceiver. because tts service, doesn't call anyting.

the best solutions start intent on broadcastreceiver activity call service.

public void onreceive(context context, intent intent) { ....      intent speechintent = new intent();     speechintent.setclass(context, readthemessage.class);     speechintent.putextra("message", message.getmessagebody().tostring());     speechintent.addflags(intent.flag_activity_new_task |  intent.flag_activity_exclude_from_recents);     context.startactivity(speechintent); .... } 

and on activity call tts service parameter extras

public class readthemessage extends activity implements oninitlistener,onutterancecompletedlistener {  private texttospeech tts = null; private string msg = "";  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     intent startingintent = this.getintent();     msg = startingintent.getstringextra("message");     tts = new texttospeech(this,this); }  @override protected void ondestroy() {     super.ondestroy();     if (tts!=null) {         tts.shutdown();     } }  // oninitlistener impl public void oninit(int status) {     tts.speak(msg, texttospeech.queue_flush, null); }  // onutterancecompletedlistener impl public void onutterancecompleted(string utteranceid) {     tts.shutdown();     tts = null;     finish(); } } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -