Question

It appears the true "From" tag of a message sent from an email service ex. 7135192435@tmomail.net has a diffrent "From" tag then what the message details reveal once the message is recieved through SMS. I want to be able to recieve SMS message via tmomail.net but the missing link lies in what exactly the phone sees as the "From" tag. I have successfully recieved SMS from other cell phones, and my broadcast reciever catches them. However I can not properly set the "From" filter in order to recieve these texts via tmomail.net. Thank you in advance for all nobel android wizards, who may take time from their projects to help. What follows is the code...

public class SmsReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        // ---get the SMS message passed in---

        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        String str = "";

        Log.d("SMS_Project", "Beginning fired!");

        if (bundle != null) {
            // ---retrieve the SMS message received---
            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]);

                String mFrom = msgs[i].getOriginatingAddress();
                String mBody = msgs[i].getMessageBody().toString();

                Log.d("SMS_Project", "The From tag follows this line");

                if (mFrom.equals("JimJohanson@JollyRanchers.com"))   {

                    Log.d("SMS_Project", "above is the from tag");

                    if (mBody.indexOf("1") == 0) {
                        str += "SMS from '" + mFrom + "'";
                        str += " :";
                        str += mBody;                   

                        str += "\n";

                        // ---display the new SMS message---
                        Log.d("SMS_Project", "Toast anyone?");
                        Toast.makeText(context, str, Toast.LENGTH_LONG).show();
                        this.abortBroadcast();

                    }
                }
            }
        }
    Log.d("SMS_Project", "No toast yet");}

Manifest Information:

<receiver android:name=".SmsReceiver" >
            <intent-filter android:priority="99999999" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

These are my permissions:

<uses-permission android:name="android.permission.RECEIVE_SMS" />

I suspect the propblem to be the phones lack of abilty to translate the email into a legit SMS. Perhaps it is a Multimedia Message type instead? Im going to keep combing the blue nowhere until I get this going. If you have any questions about what I have so far. Please let me know. Thanks.

Was it helpful?

Solution 2

Alright disregard all of my past jaw jacking... The answer to this one is to use the getEmailFrom() function.

Example :

msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);

String mFrom = msgs[i].getOriginatingAddress();
String mBody = msgs[i].getMessageBody().toString();
String mEmail = msgs[i].getEmailFrom().toString();
*Boolean mSomething = msgs[i].isEmail();*

Log.d("SMS_Project_From", mFrom);
Log.d("SMS_Project_mBody", mBody);
*Log.d("SMS_Project_Email", mEmail);*

This includes the Logcat so that you can identify exactly where the email is from.

OTHER TIPS

Im going to try and check via the mFrom string and Log.d. For anyone else encountering this Im

//inserting...

Log.d("SMS_Project", mFrom); 

//right above...

(mFrom.equals("JimJohanson@JollyRanchers.com"))

hopefully this will give me an accurate and consistent "from" tag in order to accuratley trap for a result. Can't believe its taken me this long to come up with such a simple test. Tip, learning how to properly debug and utilize LogCat is a neccessity for anyone above a copy/paste pro.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top