2011-12-24 8 views
0

受信しているSMSを分析し、送信者にメッセージを返すアプリを作成しました。 携帯電話で自動的に送信されるSMSは、デフォルトのメッセージビューアには表示されません。それをいかにするか?Androidのデフォルトのメッセージビューアに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を送信するために使用するコードです.. Private void SendSMS(String phonenumber、String message) { SmsManager manager = SmsManager.getDefault(); manager.sendTextMessage(phonenumber、null、message、null、null); } – Shijilal

+0

リンクのおかげで..私は最初のメソッドを探していた..しかし、startactivityはerrrorを示しています.. "メソッドstartActivity(インテント)は、タイプ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!!"); 

    } 

関連する問題