Hi everyone, I'm having a bit trouble in writing my app. Here is what
I intend to do: whenever a sms arrives, my receiver (registered in
manifest file) check if the message has the string defined by the user
(stored in a file).


public class SMSReceiver extends BroadcastReceiver{
        private String ACTION = "android.provider.Telephony.SMS_RECEIVED";
        private String password;
        @Override
        public void onReceive(Context context, Intent intent) {

                try {
                InputStream in = openFileInput("string.txt");
                if (in != null) {
                        InputStreamReader tmp = new InputStreamReader(in);
                        BufferedReader reader = new BufferedReader(tmp);
                        String str;
                        StringBuilder buf = new StringBuilder();
                        while ((str = reader.readLine()) != null) {
                                buf.append(str);
                        }
                        in.close();
                        password = buf.toString();
                }
        }
        catch (Throwable t) {
                Toast.makeText(this, "Exception: " + t.toString(),
Toast.LENGTH_SHORT).show();
        }

        ......//code that got the content of the sms

        if (message.equals(password)) {
                        //do something
                }

        }

}

however the InputStreamReader just doesn't work here. Is the broadcast
receiver just incapable of doing this kind of thing? or is there any
other way I can achieve my goal?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to