Op Kaushik
Op Kaushik

Reputation: 140

Receiving sms through a Service Class

I wish to make a service class that receive sms received from a broadcast receiver and get database updated for that I hava developed some code for SmsService class but it does not work. Sir pl tell me is it possible to receive SMS through a service class and update database at background. thanks and sorry for my bad pronounciation if not understand.

below is my source code of SmsService Class.

public class SmsService extends Service {

private SMSReceiver mSMSreceiver;
private IntentFilter mIntentFilter;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}
public SmsService(){
    /*dba = new DataBaseAdapter(this);*/
    mSMSreceiver = new SMSReceiver(this);
}
@Override
public void onCreate(){
    super.onCreate();       

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(ConstantClass.SMS_RECEIVED);
    registerReceiver(mSMSreceiver,mIntentFilter);
}
@Override 
public int onStartCommand(Intent intent , int flags, int type){
    return START_STICKY;
}

@Override 
public void onDestroy(){
    super.onDestroy();
    //unregisterReceiver(mSMSreceiver);

}

}

thanks in advance

Om Parkash Kaushik

Upvotes: 1

Views: 1884

Answers (1)

Jigar Pandya
Jigar Pandya

Reputation: 5977

You can check

http://mobiforge.com/developing/story/sms-messaging-android

This tutorial shows how to send and then receives, giving a notification (toast) when you receive a text.

Let me know if this helps!

Also you can check android: register application to receive sms for more details.

Thanks

Upvotes: 1

Related Questions