将全局数据放入广播接收器类时出现问题,
这是我的编码,帮助我进入广播接收器类
public class Global extends Application{
String mobileNumber;
public String getMobileNumber() {
return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}
这是我的接收器类,
public class TextMessageReceiver extends BroadcastReceiver{
Global global;
Context context;
int count;
String number;
public void onReceive(Context context, Intent intent)
{
global=(Global)context;
number = global.getMobileNumber();
Bundle bundle=intent.getExtras();
Object[] messages=(Object[])bundle.get("pdus");
SmsMessage[] sms=new SmsMessage[messages.length];
for(int n=0;n<messages.length;n++){
sms[n]=SmsMessage.createFromPdu((byte[]) messages[n]);
}
for(SmsMessage msg:sms){
if(msg.getOriginatingAddress().endsWith(number))
{
SMS.updateMessageBox(msg.getOriginatingAddress(),msg.getMessageBody(),context);
/*SMS.updateMessageBox("\nFrom: "+msg.getOriginatingAddress()+"\n"+
"Message: "+msg.getMessageBody()+"\n");*/
/*((SMS) context).delete();*/
abortBroadcast();
}
}
}
}
我需要从 getter setter 获取手机号码,但我不能,如何获取?