• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps getString() question

raubvogel

Newbie
Let's say I have a piece of code that looks like this:

Code:
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.content.BroadcastReceiver;
import android.telephony.gsm.SmsMessage;


public class SMSReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive (Context context, Intent intent)
    {
        Bundle bundle = intent.getExtras();        
        SmsMessage[] msgs = null;
        String str = ""; 
        
        if (bundle != null)
        {
            // Now retrieve the SMS message
             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]);                     
                 str += msgs[i].getMessageBody().toString();
                 if (str.equals("one-two-three"))
                 {
                      // Do something
                 }

             }

        }
        return;
    }
}

I have the "one-two-three" defined in strings.xml. How can I use it here?
 
"@string/one-two-three" is just for xml layout.

If you want to reference a string in code, you use R.string.one-two-three
 
Back
Top Bottom