Calling function from Receiver class not working.

by Lordsaibat » Wed, 21 Apr 2010 09:50:42 GMT


Sponsored Links
  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.NOTIFI



Calling function from Receiver class not working.

by Kumar Bibek » Sun, 25 Apr 2010 04:05:11 GMT


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

Thanks and Regards,
Kumar Bibek

On Apr 21, 6:50am, Lordsaibat <lordsai...@gmail.com> wrote:
>


Sponsored Links


Other Threads

1. Cara Memperbesar Internal Storage / Resize NAND Partition

Tutorial yg bagus hu...
Bintangin dulu... ^o^
Thx. ...


system
mana
atau

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android   http://www.***.com/ 

2. streaming radio relawan

mungkin ada yang mau monitoring lewat hh masing2

install yxplayer (ndak usah yang pro juga bisa)
masukkan url berikut didaftar streaming

http://180.178.92.250:8300/
http://opensource.telkomspeedy.com:8010/

saya pakai yang paling atas,

-- 
sure i have it.
no find yourself.
then ask someone else.
you too.

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

3. AndroidTab IVIO [was WTI: Mifi Smart at Indocomtech]

4. My Homescreen.

5. Is there an easier way than using x & y for multitouch

6. Repost : WTS : Google N1 & Accs

7. VOOT: Abu Merapi Sudah Sampai Bogor