Hi ,
Thanks for the wonderful post .Well I followed your method it works well on GSM
but I faced issues in Recieving CDMA SMS Messages.
Please Help.
Saurabh















IrishGrumPy wrote:Hi guys, can anyone advise what code needs to be added to this app that would automatically send a reply to the message sender saying "i got your message - busy at the moment - will ring ya later" or whatever?
If anyone can advise, it would be great!!!

import android.telephony.SmsMessage; import android.telephony.gsm.SmsMessage;edreamz wrote:I just tried out this app on the 2.2 SDk, it certainly needs some changes to the code, since the SDKs have changed a lot.
2. SmsReactor.java
- Code: Select all
package com.felix.smsreact;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SmsReactor extends BroadcastReceiver {
/** TAG used for Debug-Logging */
private static final String LOG_TAG = "SMSReactor";
/** The Action fired by the Android-System when a SMS was received.
* We are using the Default Package-Visibility */
private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
// if(message starts with SMStretcher recognize BYTE)
StringBuilder sb = new StringBuilder();
/* The SMS-Messages are 'hiding' within the extras of the Intent. */
Bundle bundle = intent.getExtras();
if (bundle != null) {
/* Get all messages contained in the Intent
* Telephony.Sms.Intents.getMessagesFromIntent(intent) does not work anymore
* hence the below changes
*/
Object[] pduObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pduObj.length];
for(int i=0;i<pduObj.length;i++)
messages[i]=SmsMessage.createFromPdu((byte[])pduObj[i]);
/* Feed the StringBuilder with all Messages found. */
for (SmsMessage currentMessage : messages){
sb.append("SMS Received From: ");
/* Sender-Number */
sb.append(currentMessage.getDisplayOriginatingAddress());
sb.append("\nMessage : ");
/* Actual Message-Content */
sb.append(currentMessage.getDisplayMessageBody());
}
}
/* Logger Debug-Output */
Log.i(LOG_TAG, "[SMSApp] onReceive: " + sb);
/* Show the Notification containing the Message. */
Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
/* Start the Main-Activity */
Intent i = new Intent(context, SmsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}

Toast.makeText(context, text, Toast.LENGTH_LONG).show();
/* Start the Main-Activity */
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{email adress});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , text);
try {
context.startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Users browsing this forum: No registered users and 7 guests