Skip to content

Instantly share code, notes, and snippets.

@mdsami
Created January 6, 2017 09:05
Show Gist options
  • Select an option

  • Save mdsami/1429ae019195b0a63b448524f435a30e to your computer and use it in GitHub Desktop.

Select an option

Save mdsami/1429ae019195b0a63b448524f435a30e to your computer and use it in GitHub Desktop.
package com.example.mdsami.receivedsms;
/**
* Created by mdsami
* 1/5/2017.
* thrusday -11.00 pm .
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class NotifyServiceReceiver extends BroadcastReceiver{
static final String ACTION ="android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
if(arg1.getAction().equalsIgnoreCase(ACTION))
{
Bundle extras = arg1.getExtras();
String strMessage = "private message";
if ( extras != null )
{
Object[] smsextras = (Object[]) extras.get( "pdus" );
for ( int i = 0; i < smsextras.length; i++ )
{
SmsMessage smsmsg = SmsMessage.createFromPdu((byte[])smsextras[i]);
String strMsgBody = smsmsg.getMessageBody().toString();
String strMsgSrc = smsmsg.getOriginatingAddress();
//Toast.makeText(GasService.this,strMessage, Toast.LENGTH_SHORT).show();
if(strMsgSrc.equals("+98801738340448"))
{
strMessage += "SMS from " + strMsgSrc + " : " + strMsgBody;
Toast.makeText(PrivatesmsService.this,strMessage, Toast.LENGTH_SHORT).show();
abortBroadcast();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment