1
我正在編碼有關短信,我有一個服務,和一個廣播接收器編程,當一個短信發送時,我得到「displayoriginatingadress,然後它自動重新發送另一個短信源數量,但我有一個錯誤/力量關閉無效目的地地址,因爲當我得到源數字(我來自法國)它是這樣的:「+33617890922」,但我需要得到它像這樣的「0617890922」,我該怎麼做? **任何幫助????SMSManager和國家代碼前綴
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」的外部庫,我認爲,我的問題來自我的意圖收到的數字?我試圖把報價沒有運氣,同樣的問題,使用一些字符串操作...跆拳道請幫助,謝謝你
更新:我注意到,字符串「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);
};
老實說,這個問題就派上了用場!謝謝! – 2012-07-22 00:50:36