gpt4 book ai didi

java - SMSManager 和国家/地区代码前缀

转载 作者:行者123 更新时间:2023-12-01 15:26:57 31 4
gpt4 key购买 nike

我正在编写一个关于短信的程序,我有一个服务和一个广播接收器,当发送短信时,我得到“显示原始地址,然后它会自动重新发送另一条短信到源号码,但我有一个错误/强制关闭无效的目标地址,因为当我获取源号码(我来自法国)时,它是这样的:“+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”的外部库,我想,我的问题是否来 self 从我的 Intent 中收到的号码?我试图引用但没有成功,使用一些字符串操作也出现同样的问题...wtf请帮助谢谢你

更新:我注意到在“lo”方法中使用字符串“str”时为空,请参阅下面的代码修改:

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);
};

最佳答案

好的,我解决了问题,无论如何,感谢您的“帮助,请查看下面的代码:

 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(){




}
public int onStartCommand(Intent itn, int num1, int flag){

str = itn.getStringExtra("id");
Toast.makeText(this, "One !" +str, Toast.LENGTH_LONG).show();

//Call here lo with str as argument:
lo(str);


return 0;
}

//Added a string here to receive the Data String from the intent(str)...

public void lo(String num){
// TODO Auto-generated method stub

//Thats all i have my data from my intent avaible here !


Toast.makeText(this, "Two !", Toast.LENGTH_LONG).show();
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();


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, null, loc, null, null);

}else{ Its work like this !
SmsManager.getDefault().sendTextMessage("+33643598356", null, "Cant Report Location", null, null);
};

关于java - SMSManager 和国家/地区代码前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10043843/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com