2011-12-24 3 views
0

나는 수신중인 SMS를 분석하고 보낸 사람에게 메시지를 다시 보내는 앱을 만들었습니다. 그러나 내 전화기에서 자동으로 보내는 SMS는 기본 메시지 뷰어에 표시되지 않습니다. 완료하는 방법 ??안드로이드의 기본 메시지 뷰어에 SMS 보내기

이 난에 쓰여진 "테스트"를 가진 SMS 수신에 SMS를 여기에

package com.lalsoft.janko; 

import java.util.Calendar; 

import android.content.BroadcastReceiver; 
import android.content.ContentValues; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.net.Uri; 
import android.os.Bundle; 
import android.telephony.gsm.SmsManager; 
import android.telephony.gsm.SmsMessage; 
import android.util.Log; 
import android.view.View; 


public class SMSReceiver extends BroadcastReceiver 
{ 
public String SendMsgBody; 


private static final String LOG_TAG = "SMSReactor"; 

@Override 
public void onReceive(Context context, Intent intent) 
{ 

    //---get the SMS message passed in--- 
    Bundle bundle = intent.getExtras();   
    SmsMessage[] msgs = null; 
    String str = ""; 
    String PhNo=""; 
    String MsgBody=""; 
    if (bundle != null) 
    { 
     //---retrieve the SMS message received--- 
     Object[] pdus = (Object[]) bundle.get("pdus"); 
     msgs = new SmsMessage[pdus.length];    
     for (int i=0; i<msgs.length; i++) 
     { 
      msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);     
      str += "SMS from " + msgs[i].getOriginatingAddress(); 
      PhNo=msgs[i].getOriginatingAddress(); 
      str += " :"; 
      str += msgs[i].getMessageBody().toString(); 
      MsgBody=msgs[i].getMessageBody().toString(); 
      str += "\n"; 
     } 


     if(MsgBody.equalsIgnoreCase("Test")) 
     { 
       SendSMS(PhNo,"Got you!!...Missile Launch initiated.Your location has been traced and the missile will hit your place in approximatly 2 Mins.. ESCAPE!!"); 
      //SendSMS2(PhNo,"Got you!!...Missile Launch initiated.Your location has been traced and the missile will hit your place in approximatly 2 Mins.. ESCAPE!!"); 
     } 

} 



/* public void SendSMS2(String phonenumber,String message) 
{ 
    startActivity(new Intent(Intent.ACTION_VIEW,Uri.fromParts(message, phonenumber, null))); 
} 
*/ 
private void SendSMS(String phonenumber,String message) 
{ 
    SmsManager manager = SmsManager.getDefault(); 
    manager.sendTextMessage(phonenumber, null, message, null, null); 
} 

} 

를 보낼 때 사용하는 코드입니다, 내 응용 프로그램이 SendSMS 방법에 sender..but에 다시 SMS를 전송, 자사의 SMS를 보내고 있지만 기본/기본 SMS 응용 프로그램에 전송 메시지가 표시되지 않습니다. 이 SMS를 기본 SMS 응용 프로그램에 표시되는 발신자에게 내 휴대폰으로 다시 보내려면 어떻게해야합니까?

+0

코드하시기 바랍니다 추가됩니다. 코드가 없다면 아무 것도 추측 할 수 없습니다. –

+0

이것은 SMS를 보내는 데 사용하는 코드입니다. 개인 무효 SendSMS (문자열 phonenumber, 문자열 메시지) { SmsManager manager = SmsManager.getDefault(); manager.sendTextMessage (phonenumber, null, message, null, null); } – Shijilal

+0

링크를 주셔서 감사합니다 .. 내가 첫 번째 방법을 찾고 있었는데 ..하지만 startactivity가 errror를 보여주고 있습니다 .. "startActivity (Intent) 메소드가 유형이 SMSReceiver" – Shijilal

답변

0

마지막으로 나는 성공을했습니다. 비록 내가 여러 곳에서이 방법을 사용해서는 안되는 곳을 읽었을 지 모르지만 ... like this이 방법을 사용하고 있습니다. 아무도이 코드를 사용하고 있지 않다면 알려주세요. 먼저 문제에 대해 .. 여기

내 코드 .. 나는이 부분에서이 메서드를 호출하고

private void SendSMS(Context c,String phonenumber,String message) 
{ 
    SmsManager manager = SmsManager.getDefault(); 
    manager.sendTextMessage(phonenumber, null, message, null, null); 

    //For displaying in Outbox 
    ContentValues values = new ContentValues(); 
    values.put("address", phonenumber); 
    values.put("body", SendMsgBody); 
    c.getContentResolver().insert(Uri.parse("content://sms/sent"), values); 
} 

는 (전체 코드는 질문 자체에 표시)입니다. 추가 컨텍스트 .. 그것은 나처럼 다른 사람을 도움이되기를 바랍니다 .. .. 내 위의 코드에서의

if(MsgBody.equalsIgnoreCase("Test")) 
    { 
      SendSMS(context,PhNo,"Got you!!...Missile Launch initiated.Your location has been traced and the missile will hit your place in approximatly 2 Mins.. ESCAPE!!"); 

    }