Android: I need to delay a Notification - android

I've create a broadcast receiver that listen to the android.provider.Telephony.SMS_RECEIVED event and creates its own notification.
I also use the same receiver in the app to update the activities when an sms is received using a callback.
The problem is that the sms app notification event is dispatched after my notification, so when I update the sms is not preset in content://sms
I would like to delay my notification if it's possible, can't find how to do it.
here's the code:
public class SmsReceiver extends BroadcastReceiver {
Context context;
int nmessages = 0;
#Override
public void onReceive(Context context, Intent intent) {
//—get the SMS message passed in—
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String messages = "";
this.context = context;
if (bundle != null)
{
//—retrieve the SMS message received—
Object[] smsExtra = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[smsExtra.length];
nmessages = SmsHolder.getNumberUnreadSms(context) +1;
for (int i=0; i<msgs.length; i++)
{
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
//take out content from sms
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
putSmsToDatabase(sms, context );
}
//—display the new SMS message—
createNotification(SmsMessage.createFromPdu((byte[])smsExtra[0]), context);
updateActivity();
}
}
public void updateActivity(){
}
private void putSmsToDatabase( SmsMessage sms, Context context )
{
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
// Create SMS row
ContentValues values = new ContentValues();
values.put("address", sms.getOriginatingAddress().toString() );
values.put("date", mydate);
values.put("body", sms.getMessageBody().toString());
// values.put( READ, MESSAGE_IS_NOT_READ );
// values.put( STATUS, sms.getStatus() );
// values.put( TYPE, MESSAGE_TYPE_INBOX );
// values.put( SEEN, MESSAGE_IS_NOT_SEEN );
}
private void createNotification(SmsMessage sms, Context context){
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
String contentTitle;
if (nmessages < 2){
contentTitle = "SMS: " + ContactsInterface.getContactDisplayNameByNumber(sms.getOriginatingAddress(), context);
}else {
contentTitle = nmessages + " " + context.getResources().getString(R.string.new_messages);
}
// construct the Notification object.
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(contentTitle)
.setContentText(sms.getMessageBody())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(getIconBitmap())
.setNumber(nmessages);
builder.setAutoCancel(true);
//(R.drawable.stat_sample, tickerText,
// System.currentTimeMillis());
// Set the info for the views that show in the notification panel.
//notif.setLatestEventInfo(this, from, message, contentIntent);
/*
// On tablets, the ticker shows the sender, the first line of the message,
// the photo of the person and the app icon. For our sample, we just show
// the same icon twice. If there is no sender, just pass an array of 1 Bitmap.
notif.tickerTitle = from;
notif.tickerSubtitle = message;
notif.tickerIcons = new Bitmap[2];
notif.tickerIcons[0] = getIconBitmap();;
notif.tickerIcons[1] = getIconBitmap();;
*/
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, Login.class);
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
// Ritardo in millisecondi
builder.setContentIntent(resultPendingIntent);
// Note that we use R.layout.incoming_message_panel as the ID for
// the notification. It could be any integer you want, but we use
// the convention of using a resource id for a string related to
// the notification. It will always be a unique number within your
// application.
nm.notify(R.drawable.ic_drawer, builder.build());
}
private Bitmap getIconBitmap() {
BitmapFactory f = new BitmapFactory();
return f.decodeResource(context.getResources(), R.drawable.ic_sms);
}
}

If you just need to do it for a specific amount of time, probably the easiest way is to use a handler and use a postDelayed(). Something like this:
// SLEEP 5 SECONDS HERE ...
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// createNotification(SmsMessage.createFromPdu((byte[])smsExtra[0]), context);
updateActivity();
}
}, 5000);
If you want to wait for another action, that's a bit more complicated.

Related

Implement BroadCastReceiver upon receiving a new SMS

I am trying to implement Broadcast receiver to implement notification pop-up upon SMS received on my Android device. However I have set a condition to detect only specific SMSs from pre-defined senders and then pop-up a notification. Here is what I have coded till now :
public class MyBroadcastReceiver extends BroadcastReceiver
{
private static final String TAG = "MyBroadCastReceiver";
String str = "";
static Context context;
String sender;
#Override
public void onReceive(Context arg0, Intent arg1)
{
// Log.i(TAG,"OnReceive ++ ");
Bundle bndl = arg1.getExtras();
SmsMessage[] msg = null;
if (null != bndl)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bndl.get("pdus");
msg = new SmsMessage[pdus.length];
if(msg[0].getOriginatingAddress().endsWith("AIRMTA") ||
msg[0].getOriginatingAddress().endsWith("ICICIB") ||
msg[0].getOriginatingAddress().endsWith("FCHRGE") ||
msg[0].getOriginatingAddress().endsWith("MYAMEX") ||
msg[0].getOriginatingAddress().endsWith("MOBIKW") ||
msg[0].getOriginatingAddress().endsWith("OLACAB") ||
msg[0].getOriginatingAddress().endsWith("HDFCB") ||
msg[0].getOriginatingAddress().endsWith("AIRMNY")
)
{
for (int i=0; i<msg.length; i++)
{
msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
// str += "SMS From " + msg[i].getOriginatingAddress();
sender = msg[i].getOriginatingAddress();
str += " :\r\n";
str += msg[i].getMessageBody().toString();
str += "\n";
context = arg0;
}
//---display incoming SMS as a Android Toast---
// Toast.makeText(arg0, str, Toast.LENGTH_SHORT).show();
//---Create a status bar notification for incoming sms-->
int mNotificationId = 001;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle(sender);
mBuilder.setContentText(str);
mBuilder.setTicker("New Message Alert!");
mBuilder.setSmallIcon(R.drawable.notification);
Intent resultIntent = new Intent(arg0, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(arg0, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotifyMgr = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
MapsFragment obj = new MapsFragment();
obj.initilizeMap();
}
}
}
}
Unfortunately the application is crashing every time I receive an SMS, be it from any sender. I am not able to understand what is going wrong with the code !
Can anyone help me out on this ?
Here is the log cat error report :
Process: com.techfrk.fetchinboxsms, PID: 21956
java.lang.RuntimeException: Unable to start receiver com.techfrk.fetchinboxsms.MyBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.telephony.SmsMessage.getOriginatingAddress()' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2616)
at android.app.ActivityThread.access$1700(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
You get a NullPointerException exception because your msg array is always empty when calling msg[0].getOriginatingAddress().endsWith().
With msg = new SmsMessage[pdus.length] you create an empty array with the size of pdus.length but this does not add any objects to it.
Instead of
if(msg[0].getOriginatingAddress().endsWith("AIRMTA") ||
msg[0].getOriginatingAddress().endsWith("ICICIB") ||
msg[0].getOriginatingAddress().endsWith("FCHRGE") ||
msg[0].getOriginatingAddress().endsWith("MYAMEX") ||
msg[0].getOriginatingAddress().endsWith("MOBIKW") ||
msg[0].getOriginatingAddress().endsWith("OLACAB") ||
msg[0].getOriginatingAddress().endsWith("HDFCB") ||
msg[0].getOriginatingAddress().endsWith("AIRMNY")
)
{
for (int i=0; i<msg.length; i++)
{
msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
// str += "SMS From " + msg[i].getOriginatingAddress();
sender = msg[i].getOriginatingAddress();
str += " :\r\n";
str += msg[i].getMessageBody().toString();
str += "\n";
context = arg0;
}
}
you should do something like
SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(arg1);
if(messages.length < 1) return;
SmsMessage sms = messages[0];
sender = sms.getOriginatingAddress();
str = sms.getMessageBody().toString();
if (sms.getOriginatingAddress().endsWith("AIRMTA")) { // add all your needed statements
// show your notification
}
Please keep in mind that this code is extremely simplified for a better understanding.

Android: detect when app is installed

I am trying to download an Android app from a server using the DownloadManager class, install it and then detect when the installation is completed. I am using two receivers: one to detect the download process and the other to detect the install process. The first receiver works properly, but the second doesn't. What I am doing wrong?
DownloadManager dm = (DownloadManager) DownloadApplicationActivity.this.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(Uri.parse(MY_LINK));
req.setTitle(MY_TITLE)
.setDescription("Downloading ....")
// download the package to the /sdcard/downlaod path.
.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
MY_PATH);
long enqueue = dm.enqueue(req);
BroadcastReceiver receiver= new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
Query query = new Query();
query.setFilterById(enqueue);
Cursor c =dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
// show a notification bar.
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,"",System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_NO_CLEAR;
Intent i = new Intent(Intent.ACTION_VIEW);
// when the notification is clicked, install the app.
i.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory() + APP_PATH)),"application/vnd.android.package-archive");
PendingIntent pendingIntent = PendingIntent.getActivity(
activity, 0, i, 0);
notification.setLatestEventInfo(activity, MY_TEXT, MY_TEXT,pendingIntent);
notification.number += 1;
notificationManager.notify( 0, notification);
//i want to detect the app's installation, I register a ne receiver
registerReceiver(installReceiver,new IntentFilter(Intent.ACTION_PACKAGE_ADDED));
}
}
};
BroadcastReceiver installReceiver= new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
Uri data = intent.getData();
String packageName = data.getEncodedSchemeSpecificPart();
Log.i("The installed package is: ", "" + packageName);
}
}
};
I solved my problem, I added
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");
before the line :
registerReceiver(installReceiver, intentFilter);
You can try the code below. This way you can get all activities that can be called by an intent and if you know the activity name and it is present in list retrieved by queryIntentActivities()..you know it is installed.
public void callQrScan()
{
Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
if(isCallable(intent1)== true){
Context context = getApplicationContext();
CharSequence text = "Scan Niet Gelukt";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else{
Context context = getApplicationContext();
CharSequence text = "Scan Niet Gelukt";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
Button tempbutton = (Button)findViewById(R.id.Button03);
tempbutton.setOnClickListener(new OnClickListener()
{
public void onClick(final View v)
{
callQrScan();
}
});
}
private boolean isCallable(Intent intent1) {
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent1,
PackageManager.MATCH_DEFAULT_ONLY);
if(list.size() > 0)
return true ;
else
return false;
}
Hope it helps :)

Best Method to store sms data in DataBase on OnReceive Method of BroadcastReceiver and then Activities get updated

I have near about six Activities and a service class with BroadcastReceiver that run in background for receiving SMS. I receive SMS on OnReceive Method of BroadcastReceiver now I would like to store incomming sms data in database for that I have made a SMSSync Class for smsProcess which pass data to dbase now I call this smsProcess on OnReceive method this work fine but I think when more sms received at same time the I got found problem I think it was due to database. Sir please tell me what is best method to store sms data after receiving it On receive and then show in activities. Sory for my bad English or if not understand. Thanks in advance sir pl revert back answer I will wait for..I tag code for On Receive method
thanks
Om Parkash Kaushik
public SMSReceiver(Context ctx){
this.context = ctx;
sync = new SMSSync(context);
dba = new DataBaseAdapter(ctx);
}
#Override
public void onReceive(Context context,final Intent intents){
if (intents.getAction().equals(ConstantClass.SMS_RECEIVED)) {
try{
Bundle bundle = intents.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
String msg=null;
String temp = null;
for (SmsMessage message : messages) {
msg = message.getMessageBody();
temp = message.getOriginatingAddress();
}
if(msg.length()>5 && msg.startsWith("<") && msg.contains(">")){
String len = msg.substring(1, 3);
int tl = temp.length();
int l = tl - no;
address = temp.substring(l,tl);
int value =Integer.valueOf(len, 16).intValue();
int index = msg.indexOf(">");
if(value == index+1){
dba.Open();
int id = dba.getCordiId(address);
Cursor cur = dba.getCoord(id);
if(cur!=null)
cur.moveToFirst();
final String Phnumber = cur.getString(cur.getColumnIndex(DataBaseAdapter.Key_MbNo));
if(Phnumber.equals(address)){
int count = dba.getDeviceCount(ConstantClass.dbName[1]);
if(count<=0){
dba.InsertCurrentCoord(id,id);
}else{
Strsql = new String("UPDATE " + ConstantClass.dbName[1] + " SET " + DataBaseAdapter.Key_ReceiverCoord + " = " +
Integer.toString(id) + " WHERE " + DataBaseAdapter.Key_ID + " = ?");
dba.UpdateQuery(Strsql, Integer.toString(1));
}
dba.Close();
sync.smsProcess(msg);
abortBroadcast();
/************Now deleting the SMS from the Inbox*********************/
removeMessage(SMSReceiver.this.context, Phnumber);
if(msg.substring(3, 4).equals("2"))
ConstantClass.isAuditrequestSend = false;
/*******after receiving the sms opening the Main Screen.*****************/
if(ConstantClass.Clear_Main_Screen==true){
Intent intent = new Intent(context,ZigbeeActivity.class);
context.startActivity(intent);
}
}else{
Toast.makeText(SMSReceiver.this.context, address, Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(SMSReceiver.this.context, "message Corrupt" + address, Toast.LENGTH_LONG).show();
}
}
}
}catch(Exception e){
dlg = new ExceptionDialog(SMSReceiver.this.context,"On Sms Receiver" + address ,e.getMessage());
dlg.show();
}
}
}
I have done the same application related to yours. But instead of saving all received sms i want to save only bank transaction related sms. I hope the following code will helps you..
ReceiveSms.java
if(smsg.contains("credit") /***********/ || msg.contains("amount"))
{
Toast.makeText(context, "message related to transcation", Toast.LENGTH_SHORT).show();
dbh.smsservice(smsg);
}
DbHandler.java
public void smsservice(String sms)
{
// TODO Auto-generated method stub
String smessg="INSERT INTO SMSDETAILS(SMSMESS) VALUES('"+sms+"') ";
sdb.execSQL(smessg);
System.out.println("values of sms inserted"+smessg);
}

How "deliveryIntent" works in Android SMS framework?

Android documentation for SMSManagers sendTextMessage function
public void sendTextMessage (String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent)
deliveryIntent if not NULL this PendingIntent is broadcast when the message is delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu")
I could not understand if deliveryIntent is fired when SMS is delivered to destinationAddress or scAddress and what is the meaning of "raw pdu of the status report is in the extended data ("pdu")" and how to get that report? .
I appreciate your effort.
It is broadcast when message is delivered to destinationAddress.
The PDU may be extracted from the Intent.getExtras().get("pdu") when registered BroadcastReceiver receives the Intent broadcast you define with PendingIntent.getBroadcast(Context, int requestCode, Intent, int flags). For example:
private void sendSMS(String phoneNumber, String message) {
String DELIVERED = "DELIVERED";
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
registerReceiver(
new BroadcastReceiver() {
#Override
public void onReceive(Context arg0, Intent arg1) {
Object pdu = arg1.getExtras().get("pdu");
... // Do something with pdu
}
},
new IntentFilter(DELIVERED));
SmsManager smsMngr = SmsManager.getDefault();
smsMngr.sendTextMessage(phoneNumber, null, message, null, deliveredPI);
}
Then you need to parse extracted PDU, SMSLib should be able to do that.
Just to build on a.ch's answer, heres how you can extract the delivery report from an intent:
public static final SmsMessage[] getMessagesFromIntent(Intent intent) {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
if (messages == null || messages.length == 0) {
return null;
}
byte[][] pduObjs = new byte[messages.length][];
for (int i = 0, len = messages.length; i < len; i++) {
pduObjs[i] = (byte[]) messages[i];
}
byte[][] pdus = new byte[pduObjs.length][];
SmsMessage[] msgs = new SmsMessage[pdus.length];
for (int i = 0, count = pdus.length; i < count; i++) {
pdus[i] = pduObjs[i];
msgs[i] = SmsMessage.createFromPdu(pdus[i]);
}
return msgs;
}
Full credit to the great project at: http://code.google.com/p/android-smspopup/

Refreshing my ListView everytime i got a new SMS

I realized,there're some questions here, but i think my code is really different from them (i'm a beginner) and i can't understand their answers!
So i want to refresh my ListView everytime i receive a SMS, i tried to use cursor.requery(); and some methods which i found on google but it's still not working.
This is my code :
public class SMSActivity extends Activity implements OnItemClickListener {
ArrayList<String> smsList = new ArrayList<String>();
// String ADDRESS[];
// int total = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Uri.parse("content://sms/inbox"), null, null,
null, null);
int indexBody = cursor.getColumnIndex("body");
int indexAddr = cursor.getColumnIndex("address");
if (indexBody < 0 || !cursor.moveToFirst())
return;
smsList.clear();
do {
String str = "Sender : " + cursor.getString(indexAddr) + "\n"
+ cursor.getString(indexBody);
smsList.add(str);
// ADDRESS[total] = cursor.getString(indexAddr);
// total++;
} while (cursor.moveToNext());
ListView lvSms = (ListView) findViewById(R.id.SMSList);
lvSms.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, smsList));
// cursor.requery();
lvSms.setOnItemClickListener(this);
}
EDITED :
And this is the Class where i extends it with BroadcastReceiver :
public class SMSReceiver extends BroadcastReceiver {
private static final int NOTIF_ID = 0;
#Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Bundle bundle = arg1.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++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str += "You Get New SMS from " + msgs[i].getOriginatingAddress();
str += " :"; str += msgs[i].getMessageBody().toString();
str += "\n";
Toast.makeText(arg0, str, Toast.LENGTH_SHORT).show();
NotificationManager nm = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
String tickerText = str;
Notification notif = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());
notif.flags = Notification.FLAG_AUTO_CANCEL;
String contentTitle = msgs[i].getOriginatingAddress();
String contentText = msgs[i].getMessageBody().toString();
Intent intent = new Intent(arg0, SMSReply.class);
PendingIntent pi = PendingIntent.getActivity(arg0, 0, intent, 0);
notif.setLatestEventInfo(arg0, contentTitle, contentText, pi);
notif.defaults = Notification.DEFAULT_ALL;
nm.notify(NOTIF_ID, notif);
String tempSMS = msgs[i].getOriginatingAddress();
Intent pass = new Intent();
Bundle bundlePass = new Bundle();
bundlePass.putString("key", tempSMS);
pass.putExtras(bundlePass);
}
}
}
I don't understand how to link those two Class so everytime the BroadcastReceiver works(new SMS come) my ListView will be updated(just like the SMS app in your phone)
Thanks All.
Define adapter as global public variable,
ArrayAdapter<String> adapter;
inside onCreate() assign it,
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, smsList));
in your BroadcastReceiver access the smsList and add to it the new sms,
then access your adapter this way,
adapter.notifyDataSetChanged();
this function will notify the adapter that smsList values have been changed and will update the list.
You can create a BroadcastReceiver class with an abstract method, like this:
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent arg1) {
...
do your stuff here
...
myAbsMethod(newSms);
}
public abstract void myAbsMethod(String sms);
}
Then, in your activity you do something like this:
public class MyActivity extends Activity {
private final MyReceiver myReceiver;
private ArrayList<String> smsList = new ArrayList<String>();
...
public MyActivity() {
myReceiver = new MyReceiver() {
#Override
public void myAbsMethod(String sms) {
smsList.add(sms);
}
};
}
#Override
public void onCreate(Bundle savedInstanceState) {
...
IntentFilter filterState = new IntentFilter(YOUR_SMS_ACTION);
registerReceiver(myReceiver, filterState)
}
...
#Override
public void onDestroy() {
...
unregisterReceiver(myReceiver);
}
}
So, basically, you're registering this receiver inside your activity class, then whenever you receive this broadcast, your activity will listen, and you can do whatever you want in this overridden abstract method.

Categories

Resources