از طریق این بردکست تونستم پیامک های ورودی رو بگیرم و داخل یه لیست ذخیره کنم. الان میخام که فقط از یه شماره خاص که پیام میاد، داخل برنامه بره و بقیه پیام ها داخل مسنجر خود گوشی بره. لطفا راهنمایی کنید
public class SMSReceiver extends BroadcastReceiver
{
// SmsManager class is responsible for all SMS related actions
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Get the SMS message received
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
// A PDU is a "protocol data unit". This is the industrial standard for SMS message
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
// This will create an SmsMessage object from the received pdu
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
// Get sender phone number
String phoneNumber = sms.getDisplayOriginatingAddress();
String sender = phoneNumber;
String message = sms.getDisplayMessageBody();
String formattedText = String.format(context.getResources().getString(R.s tring.sms_message), sender, message);
// Display the SMS message in a Toast
Toast.makeText(context, formattedText, Toast.LENGTH_LONG).show();
HistoryActivity inst = HistoryActivity.instance();
inst.updateList(formattedText);
}
}
} catch (Exception e) {
e.printStackTrace();