android - how to get my app to respond to a SMS from a specific number -
i trying build app response sms of specific number, more demonstration want code this:
if(number == +232344322) { } else { nothing }
so simplest way in android ???
you need create broadcastreceiver
invoked when sms received.in onreceive
of broadcastreceiver
write code retrive number of sms sender , compare number , perform task based on that.
public class receivesms extends broadcastreceiver { @override public void onreceive(context context, intent intent) { final bundle bundle = intent.getextras(); if (bundle != null) { final object[] pdusobj = (object[]) bundle.get("pdus"); (int = 0; < pdusobj.length; i++) { smsmessage currentmessage = smsmessage.createfrompdu((byte[]) pdusobj[i]); string phonenumber = currentmessage.getdisplayoriginatingaddress(); string message = currentmessage.getdisplaymessagebody(); log.v("ranjapp", phonenumber + " " + message); if (phonenumber.equals("+91xxxxxx"))) { //do }else{ //do nothing } } } } }
in androidmanifest.xml need add:
**the receiver intent-filter within
<application>
tag<receiver android:name=".receivesms" android:exported="true" android:permission="android.permission.broadcast_sms"> <intent-filter> <action android:name="android.provider.telephony.sms_received" /> <action android:name="android.provider.telephony.sms_deliver" /> </intent-filter> </receiver>
permission:
<uses-permission android:name="android.permission.receive_sms"/>
<uses-permission android:name="android.permission.read_sms"/>
Comments
Post a Comment