我正在编写一个关于 SMS 的程序,我有一个服务和一个广播接收器,当发送一条短信时,我得到“显示来源地址,然后它会自动将另一个短信重新发送到源号码,但我有一个错误/强制关闭无效的目标地址,因为当我得到源号码(我来自法国)时它是这样的:“+33617890922”但我需要像这样“0617890922”,我该怎么做?**任何帮助????
public void onReceive(Context c, Intent intent) {
// TODO Auto-generated method stub
mContext = c;
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) pudsBundle.get("pdus");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);
Toast.makeText(c, "Service SMS Started OK !", Toast.LENGTH_LONG).show();
Toast.makeText(c, "SMS Received : "+messages.getMessageBody(),
Toast.LENGTH_LONG).show();
String str = messages.getMessageBody();
String num = messages.getDisplayOriginatingAddress();
String str1= PhoneNumberUtils.formatNanpNumber(num);
if(messages.getMessageBody().contentEquals("klmj")){
if (intent.getAction().equals(ACTION_RECEIVE_SMS)){
Intent serviceIntent = new Intent(mContext, ServiceLocation.class);
serviceIntent.putExtra("id", str1);
mContext.startService(serviceIntent);
}
…………………………
好的,问题不是来自“+33”,因为我试图用“+33677890098”替换目的地地址以发送短信,它的工作,我丢失了,这是我从广播接收器获得的数据损坏了吗?这里有一些代码我也不知道如何使用我发现的名为“phoneutil”的外部库,我想,我的问题是来自我的意图收到的号码吗?我试图在没有运气的情况下引用,使用一些字符串操作也出现同样的问题...... wtf请帮助谢谢你
更新:我注意到字符串“str”在“lo”方法中使用时为空,请参阅下面的代码修改:
public class ServiceTe extends Service{
private final String ACTION_RECEIVE_SMS = "android.provider.Telephony.SMS_RECEIVED";
private String initData;
int myLatitude , myLongitude;
private String loc;
private String str;
private String num;
public void onCreate(){
lo();
}
public int onStartCommand(Intent itn, int num1, int flag){
str = itn.getStringExtra("id");
Toast.makeText(this, "One !" +str, Toast.LENGTH_LONG).show();
return 0;
}
public void lo(){
// TODO Auto-generated method stub
Toast.makeText(this, "Two !", Toast.LENGTH_LONG).show();
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
//This Toast show : "" , Nothing...
Toast.makeText(this, str, Toast.LENGTH_LONG).show();
int cid = cellLocation.getCid();
int lac = cellLocation.getLac();
if(RqsLocation(cid, lac)){
loc = (
String.valueOf((float)myLatitude/1000000)
+ " : "
+ String.valueOf((float)myLongitude/1000000));
Its doesnt work like this,Force Close , and invalid DestinationAddress error
SmsManager.getDefault().sendTextMessage(str OR this : itn.getStringExtra("id"); , null, loc, null, null);
}else{ Its work like this !
SmsManager.getDefault().sendTextMessage("+33643598356", null, "Cant Report Location", null, null);
};