1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class MainSms extends BroadcastReceiver
{
private final String ACTION_RECEIVE_SMS = "android.provider.Telephony.SMS_RECEIVED";
private static Pattern pattern;
private static Matcher matcher;
static final String DATE_PATTERN = "(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)";
String splitString;
String[] date;
String delim=" ";
@Override
public void onReceive(Context context, Intent intent)
{Toast.makeText(context, "Action", Toast.LENGTH_SHORT).show();
if (intent.getAction().equals(ACTION_RECEIVE_SMS))
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (messages.length > -1)
{
final String messageBody = messages[0].getMessageBody();
for(SmsMessage message : messages)
{
String messagBody=messageBody.toLowerCase();
String[] messageSplit=messagBody.split(delim);
int count=messageSplit.length;
int j=0;
for (int i=0; i<count;i++)
{
pattern = Pattern.compile(DATE_PATTERN);
matcher = pattern.matcher(messageSplit[i]);
if(matcher.find())
{
date[j]=matcher.group();
Toast.makeText(context,date[j] , Toast.LENGTH_LONG).show();
j++;
}
}
if (messagBody.contains("reunion")){
Log.i("",message.getOriginatingAddress()+"::"+message.getMessageBody());
Log.i("",message.getOriginatingAddress()+"::"+messagBody);
}
Toast.makeText(context, "Parfait", Toast.LENGTH_SHORT).show();
}
}
}
}
}
} |
Partager