How do you automate text message in the broadcast receiver class.. I have a class implementing the broadcast receiver... I want to also automatically send a text message from this class too.. Is it possible? If so how??
I cant figure it out. and i've looked through android docs.
For example
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage []msgs = null;
String str = "";
if(bundle != null){
Object[]pdus = (Object[])bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
m开发者_运维知识库sgs[i]= SmsMessage.createFromPdu((byte[])pdus[i]);
phonenumber += msgs[i].getOriginatingAddress();
str += msgs[i].getMessageBody().toString();
}
if(str.contains(houseNumber))
Toast.makeText(context, phonenumber + str, Toast.LENGTH_SHORT).show();
phonenumber = MainActivity.phoneNumber;
houseNumber = MainActivity.houseNumber;
IF it possible to send a text message automatically using smsManager in my if statement in the onReceive? If so how. Thanks Everyone
use following code
SMSSender smsSender = new SMSSender(mContext);
smsSender.sendSMS(phoneNumber, messageString);
精彩评论