我已經實現了一個名爲Reciever的擴展廣播接收器... 我想要的是,要麼顯示接收到的短信在吐司我想發送它在另一個Java類,這是從活動擴展。 。這裏是類的代碼..Android ListView項目ID
package com.sms.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class Reciever extends BroadcastReceiver {
final SmsManager sms = SmsManager.getDefault();
String msg="";
String number="";
@Override
public void onReceive(Context arg0, Intent inn)
{
Bundle bndl = inn.getExtras();
try
{
if(bndl != null)
{
Object[] sms_details= (Object[]) bndl.get("pdus");
for(int i=0 ; i<sms_details.length ; i++)
{
SmsMessage message = SmsMessage.createFromPdu((byte[]) sms_details[i]);
number = message.getDisplayOriginatingAddress();
msg = message.getDisplayMessageBody();
// Toast.makeText(arg0, "Sender Number = "+number+" Your Message = "+msg, Toast.LENGTH_LONG).show();
}
Intent in = new Intent();
in.setAction("SMS_RECIEVED_ACTION");
in.putExtra("msg", msg);
in.putExtra("num", number);
arg0.sendBroadcast(in);
}
}
catch(Exception e)
{
Toast.makeText(arg0, "Error", Toast.LENGTH_SHORT).show();
}
}
}
現在我還有一個名爲類短信reciver包含2個edittexts中,我想顯示這些封郵件......
package com.sms.sms;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
public class recieve_sms extends Activity {
EditText edt_msg;
Bundle bndl;
Button btn_rply;
EditText edt_num;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recieve);
edt_msg = (EditText) findViewById(R.id.editText2);
edt_num = (EditText) findViewById(R.id.editText1);
btn_rply = (Button) findViewById(R.id.button1);
//here should be some code which recieve msg from Reciever class and show in edittexts..
}
}
什麼是您的問題.. – Zyoo