android - speak failed:tts engine connection not fully setup -
package com.example.trynot; import java.io.ioexception; import java.util.calendar; import java.util.locale; import java.util.properties; import java.util.logging.level; import java.util.logging.logger; import javax.mail.address; import javax.mail.bodypart; import javax.mail.flags; import javax.mail.folder; import javax.mail.message; import javax.mail.messagingexception; import javax.mail.multipart; import javax.mail.nosuchproviderexception; import javax.mail.passwordauthentication; import javax.mail.session; import javax.mail.store; import javax.mail.flags.flag; import javax.mail.search.flagterm; import com.example.trynot.mainactivity; import com.example.trynot.r; import android.annotation.suppresslint; import android.app.activity; import android.app.activitymanager; import android.app.activitymanager.runningserviceinfo; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.context; import android.content.intent; import android.database.sqlite.sqlitedatabase; import android.os.asynctask; import android.os.bundle; import android.os.handler; import android.sax.startelementlistener; import android.speech.tts.texttospeech; import android.support.v4.app.notificationcompat; import android.support.v4.app.notificationcompat.builder; import android.util.log; import android.view.menu; import android.view.menuitem; import android.widget.toast; import android.speech.tts.texttospeech; public class mainactivity extends activity { public static context c,b; public static intent serviceintent; private static int mynotificationid; public static class readmailsample extends asynctask<string,string,void> implements texttospeech.oninitlistener{ message message; private texttospeech tts; static string command, phonenumber, type, priority, name, time_stamp, imei, opt1, opt2, opt3, fromsubstring; properties properties = null; private session session = null; private store store = null; private folder inbox = null; string username="avarote1994@gmail.com" ; // provide recepient email id string password="amul11111994" ; // provide recepient password static sqlitedatabase db; boolean flag=false; context acn; //private bundle savedinstancestate; protected void doinbackground(string...params){ // separate thread run in background try{ readmails(); } catch(exception e){ logger logger = logger.getanonymouslogger(); logger.log(level.info, "an exception thrown", e); } return null; } readmailsample(sqlitedatabase db){ this.db = db; } readmailsample(){ } readmailsample(context cn){ acn=cn; } @override protected void onpreexecute() { super.onpreexecute(); tts = new texttospeech(c, readmailsample.this); } @override protected void onprogressupdate(string... values) { try { system.out.println("---------------------adasd-----------" + time_stamp); speakout(); shownotification(); } catch(exception e){ e.printstacktrace(); } } @override public void ondestroy() { // don't forget shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } // super.ondestroy(); } @override public void oninit(int status) { if (status == texttospeech.success) { tts.speak(command, texttospeech.queue_flush, null); int result = tts.setlanguage(locale.us); if (result == texttospeech.lang_missing_data || result == texttospeech.lang_not_supported) { log.e("tts", "this language not supported"); } else { speakout(); } } else { log.e("tts", "initilization failed!"); } } private void speakout() { tts.speak(command, texttospeech.queue_flush, null); } public void shownotification() { pendingintent notificationintent = preparependingintent(); notification notification = createbasicnotification(notificationintent); displaynotification(notification); } @suppresslint("inlinedapi") private pendingintent preparependingintent() { intent intent=new intent(c,mainactivity.class); intent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task); pendingintent pendingintent = pendingintent.getactivity( c, 0, intent, pendingintent.flag_update_current); return pendingintent; } private notification createbasicnotification(pendingintent notificationintent) { notificationcompat.builder builder = new builder(c); long[] vibrationpattern = {0, 200, 800, 200, 600, 200, 400, 200, 200, 200, 100, 200, 50, 200, 50, 200, 50, 200, 50, 200}; notification notification = builder .setsmallicon(r.drawable.ic_launcher) .setcontenttitle("medication reminder") .setcontenttext(command) .setautocancel(true) .setcontentintent(notificationintent) .setwhen(calendar.getinstance().gettimeinmillis() + 1000*60+60) .setvibrate(vibrationpattern) .build(); return notification; } private void displaynotification(notification notification) { notificationmanager notificationmanager = (notificationmanager)c.getsystemservice(context.notification_service); mynotificationid=(int) system.currenttimemillis(); notificationmanager.notify(mynotificationid , notification); speakout(); } public void readmails() throws ioexception{ system.out.println("readmail hi"); properties = new properties(); // setting imap server access recepient's email properties.setproperty("mail.host", "imap.gmail.com"); properties.setproperty("mail.port", "995"); properties.setproperty("mail.transport.protocol", "imaps"); while(true){// continuously monitor incoming mail's //string cq = "select * login4"; //cursor c = db.rawquery(cq, null); // c.movetofirst(); //final string username = c.getstring(0); //final string password = c.getstring(1); //string cloud = "avarote1994@gmail.com"; // authenticate , instance of session server session = session.getinstance(properties,new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(username, password); } }); try { store = session.getstore("imaps"); store.connect(); inbox = store.getfolder("inbox"); // access inbox of recepient's email id inbox.open(folder.read_write); // open inbox in read-write mode message messages[] = inbox.search(new flagterm(new flags(flag.seen), false)); //search inbox unread mails system.out.println("number of mails = " + messages.length); (int = 0; < messages.length; i++) { // process unread mails message = messages[i]; address[] = message.getfrom(); string from1 = from[0].tostring(); system.out.println(from1); if(from1.contains("<")){ int start = from1.indexof("<"); int end = from1.indexof(">"); fromsubstring = from1.substring(start+1,end); // retrieve sender's email id } else{ fromsubstring = from1; } system.out.println(fromsubstring); //if(fromsubstring.equals(cloud)){ // check whether mail cloud string[] subject = message.getsubject().split(","); // split subject system.out.println("hi"); type = subject[0]; // store details in respective variables phonenumber =subject[1]; name = subject[2]; system.out.println(type); system.out.println(phonenumber); system.out.println(name); //string body=message.getcontenttype().tostring(); // system.out.print(body); processmessagebody(message); system.out.println("--------------------------------"); // } } inbox.close(true); store.close(); } catch (nosuchproviderexception e) { e.printstacktrace(); } catch (messagingexception e) { e.printstacktrace(); } } } public void processmessagebody(message message) { try { object content = message.getcontent(); string msg=content.tostring(); system.out.println(msg); if (content instanceof multipart) { // if mail has multipart message multipart multipart = (multipart) content; procesmultipart(multipart); } else{ system.out.println("content = "+content); processsinglepart(content.tostring()); } } catch (ioexception e) { e.printstacktrace(); } catch (messagingexception e) { e.printstacktrace(); } } public void processsinglepart(string content){ string[] body = content.split(","); // split contents of body system.out.println('1'); time_stamp = body[0]; // store details in respective variables command = body[3]; system.out.println(time_stamp); //tts.speak(time_stamp, texttospeech.queue_flush, null); publishprogress(command); } public void procesmultipart(multipart content) { system.out.println("amulya"); try { bodypart bodypart = content.getbodypart(0); // retrieve contents body object o; o = bodypart.getcontent(); if (o instanceof string) { system.out.println("content multipart= "+o.tostring()); processsinglepart(o.tostring()); } } catch (ioexception e) { e.printstacktrace(); } catch (messagingexception e) { e.printstacktrace(); } } } @override protected void oncreate(bundle savedinstancestate) { c = this.getapplicationcontext(); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (!ismyservicerunning()){ serviceintent = new intent(getapplicationcontext(),myservice.class); c.startservice(serviceintent); } final sqlitedatabase db = openorcreatedatabase("gdv_db_new_0711", context.mode_private, null); db.execsql("create table if not exists login4(mailid varchar,password varchar);"); db.execsql("create table if not exists client_data(type varchar,time_stamp varchar,priority varchar,result varchar,opt1 varchar,opt2 varchar,opt3 varchar);"); readmailsample rd=new readmailsample(getapplicationcontext()); system.out.println("hello"); rd.execute(); system.out.println("------xvsdfsdfsd---------aefaefa-----------------"); } private boolean ismyservicerunning() { activitymanager manager = (activitymanager) getsystemservice(context.activity_service); (runningserviceinfo service : manager.getrunningservices(integer.max_value)) { if (myservice.class.getname().equals(service.service.getclassname())) { return true; } } return false; } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
i implementing texttospeech fuctionality. reading body of email , notifying. want convert body of mail speech notification.i getting above error. notification working fine not getting converted speech
Comments
Post a Comment