0
的默認消息查看器中發送短信我已經創建了一個應用程序,分析正在接收的SMS並將消息發送回發件人。 但是那些由我的手機自動發送的短信不會顯示在默認的信息查看器中。如何完成它?顯示在Android
這是我用它來發送短信
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);
}
}
這裏當收到帶有「測試」上寫短信的代碼,我的應用程序發送短信回sender..but在這個SendSMS方法,它發送SMS,但發送消息沒有顯示在本機/默認SMS應用程序中。我應該怎麼做才能將此短信通過手機發送回發件人,並顯示在本機SMS應用程序中。
代碼請。沒有代碼,我們不能承擔任何事情。 – 2011-12-24 07:34:17
這是我用來發送短信的代碼.. private void SendSMS(String phonenumber,String message) { SmsManager manager = SmsManager.getDefault(); manager.sendTextMessage(phonenumber,null,message,null,null); } – Shijilal 2011-12-24 08:24:18
感謝您的鏈接..我正在尋找第一種方法..但是startactivity顯示errror ..「方法startActivity(意圖)是未定義的類型SMSReceiver」 – Shijilal 2011-12-25 05:50:34