What doesn't work? Can you be more specific about your problem?

Thanks and Regards,
Kumar Bibek

On Apr 21, 6:50 am, Lordsaibat <[email protected]> wrote:
> I have a SMSReceiver class that needs to pass the phone number and
> message to another class.  Which works but when I call that class I
> need the function to read preference to compare if it needs to execute
> another function.  So here is the code.
>
> SMSReceiver
>
> public void onReceive(Context context, Intent intent) {
>                 // TODO Auto-generated method stub
>
>                 //--get the SMS message passed in --
>                 Bundle bundle = intent.getExtras();
>                 SmsMessage[] msgs = null;
>                 String str = "";
>                 String from;
>                 String mymsg;
>
>                 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]);
>                                 str += "Sms from " + 
> msgs[i].getOriginatingAddress();
>                                 from = msgs[i].getOriginatingAddress();
>                                 str += " :";
>                                 str += msgs[i].getMessageBody().toString();
>                                 mymsg = msgs[i].getMessageBody().toString();
>                                 str += "\n";
>
>                                 Log.d("SMSReceiver from", from);
>                                 Log.d("SMSReceiver mymsg", mymsg);
>
>                                 //calling the class
>                                 caralarm ca = new caralarm();
>                                 ca.texttest(from, mymsg);
>
>                         }
>                         //display the new sms message
>                         Toast.makeText(context, str, 
> Toast.LENGTH_SHORT).show();
>
>                 }
>         }
>
> CarAlarm
>
> public void texttest(String number, String message){
>
>         //These cause nullpointer exceptions
>     //SharedPreferences SPNumber = getSharedPreferences("Number",
> MODE_WORLD_READABLE);
>     //SharedPreferences SPPassword = getSharedPreferences("Password",
> MODE_WORLD_READABLE);
>     //SharedPreferences SPOften = getSharedPreferences("Often",
> MODE_WORLD_READABLE);
>
>         //Number = SPNumber.getString("Number", "NullNumber");
>     //Password = SPPassword.getString("Password", "NullPassword");
>     //Often = SPOften.getString("Often", "NullOften");
>
>         //need to read number from preferences
>         //these only work if Settings2 was loaded before this is called
>         Number = Settings2.Number;
>         Password = Settings2.Password;
>         Often = Settings2.Often;
>
>         String brokenmsg[];
>         brokenmsg = message.split(";");
>         int brokenmsglength = brokenmsg.length;
>
>           if (number == Number){
>                   Log.d ("texttest", "good number");
>           }else{
>           Log.d ("texttest", "bad number");
>           }
>
>           //not firing off even if it is the same
>           if (message.toString() == "Alert"){
>                   Log.d ("message", "YAY!! in Alert");
>                   String ns = Context.NOTIFICATION_SERVICE;
>                   NotificationManager mNotificationManager = 
> (NotificationManager)
> getSystemService(ns);
>
>                   int icon = R.drawable.caralarmicon;
>               CharSequence tickerText = "Car Alarm";
>               long when = System.currentTimeMillis();
>
>               Notification notification = new Notification(icon, tickerText,
> when);
>
>               long[] vibrate = {0,100,200,300};
>               notification.vibrate = vibrate;
>
>               notification.ledARGB = 0xffffffff;
>               notification.ledOnMS = 300;
>               notification.ledOffMS = 1000;
>               notification.flags |= Notification.FLAG_SHOW_LIGHTS;
>
>             Context context = getApplicationContext();
>                 CharSequence contentTitle = "Car Alarm";
>                 CharSequence contentText = "Alarm";
>                 Intent notificationIntent = new Intent(this, caralarm.class);
>                 PendingIntent contentIntent = PendingIntent.getActivity(this, 
> 0,
> notificationIntent, 0);
>
>                 notification.setLatestEventInfo(context, contentTitle,
> contentText, contentIntent);
>                 final int HELLO_ID = 1;
>
>                 mNotificationManager.notify(HELLO_ID, notification);
>           }
>   }
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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