2012-04-06 3 views
1

나는 SMS에 관한 프로그램을 코딩하고 있습니다. 서비스 및 브로드 캐스트 리시버가 있습니다. SMS가 보내지면 "displayoriginatingadress"가 표시되고 자동으로 소스 번호에 다른 SMS를 다시 보냅니다. 내가 버그 번호/무효 목적지 주소 beacause 내가이 소스 코드를 얻을 때 (나는 프랑스에서 오전)와 같은 가까이 : "+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"beacause에서 "+33677890098"및 그 작업에 의해, 내가 잃어버린 메신저에 의해 보낼 sendadadress를 대체하려고, 내 방송 수신기에서 얻은 데이터가 손상되었습니다 ~ ?? 여기에 몇 가지 코드 또한 내 생각에 "phoneutil"이라고 불리는 것으로 발견 된 외부 라이브러리를 사용하는 방법을 모르겠다. 나의 문제는 제 의도대로받은 번호에서 오는 것입니까? 나는 행운과 견적을 넣으려고했는데 문자열 연산을 사용하여 같은 문제가 발생했습니다 ... 감사합니다. 도와주세요.

업데이트 : "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); 
     }; 
+0

솔직히,이 질문에 편리 왔어요! 감사! –

답변

1

OK, 아래의 코드를 봐 :

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