SMS Reader is an application that read all incoming SMS loudly.And it has feature of reading existing SMS using navigation keys.
package com.sms.reader;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class ReadSMSActivity extends Activity implements TextToSpeech.OnInitListener{
private ImageView prevBtn;
private ImageView nextBtn;
private ImageView speakBtn;
private TextView msgTxt;
private TextView inboxTxt;
private TextView fromTxt;
private TextToSpeech tts;
int totalSMS=0;
int smsIndex=0;
String from="";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
tts = new TextToSpeech(this, this);
nextBtn = (ImageView) findViewById(R.id.nextImg);
prevBtn = (ImageView) findViewById(R.id.prevImg);
speakBtn = (ImageView) findViewById(R.id.speakImg);
msgTxt= (TextView) findViewById(R.id.msgTxt);
inboxTxt= (TextView) findViewById(R.id.inboxTxt);
fromTxt=(TextView) findViewById(R.id.fromTxt);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur1 = getContentResolver().query(uriSMSURI, null, null, null,null);
totalSMS=cur1.getCount();
inboxTxt.setText("Inbox("+(smsIndex+1)+"/"+totalSMS+")");
msgTxt.setText(readSMS());
fromTxt.setText("From: "+from);
nextBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
smsIndex=smsIndex+1;
msgTxt.setText(readSMS());
inboxTxt.setText("Inbox("+(smsIndex+1)+"/"+totalSMS+")");
fromTxt.setText("From: "+from);
}
} );
speakBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String text = msgTxt.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
} );
prevBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
smsIndex=smsIndex-1;
msgTxt.setText(readSMS());
inboxTxt.setText("Inbox("+(smsIndex+1)+"/"+totalSMS+")");
fromTxt.setText("From: "+from);
}
} );
}
public String readSMS(){
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
if(smsIndex==-1)
smsIndex=totalSMS-1;
else if( smsIndex==totalSMS)
smsIndex=0;
if (cur.moveToPosition(smsIndex)) {
try {
sms = cur.getString(11) ;
from=cur.getString(2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
sms="You don't have SMS";
return sms;
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} /*else {
btnSpeak.setEnabled(true);
speakOut();
}*/
} else {
Log.e("TTS", "Initilization Failed!");
}
}
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}
package com.sms.reader;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
public class SMSReaderActivity extends BroadcastReceiver{
/* private SharedPreferences preferences;
TTSActivity tTSActivity = null;
public void setMainActivityHandler(TTSActivity tTSActivity){
this.tTSActivity = tTSActivity;
}
*/
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
Log.d("APP","SMS Receiver started."+msgBody);
Intent intent1 = new Intent(context, TTSActivity.class);
intent1.putExtra("sms-text", msgBody);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
}
}
package com.sms.reader;
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/*import com.sms.reader.R;*/
import android.widget.ImageView;
public class TTSActivity extends Activity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
private TextToSpeech tts;
private EditText txtText;
private ImageView inboxBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tts = new TextToSpeech(this, this);
txtText = (EditText) findViewById(R.id.txtText);
inboxBtn = (ImageView) findViewById(R.id.inboxImg);
Intent intent = getIntent();
String sms = intent.getExtras().getString("sms-text");
txtText.setText(sms);
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("You Got SMS. Shall I read ?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
// button on click event
inboxBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(TTSActivity.this, ReadSMSActivity.class);
startActivity(intent);
}
} );
}
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} /*else {
btnSpeak.setEnabled(true);
speakOut();
}*/
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
speakOut();
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
}


can u upload the androidmanifest file . . strings.xml .... n view file ?