BRITTER BAIRE | Bring Your Own Solution

Dhaka

Team Updates

package com.theeeceguy.eqresq;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.provider.Telephony;
import android.support.v7.app.AlertDialog;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SmsListener extends BroadcastReceiver {
String msgBody;
String msg_from;
@Override
public void onReceive(final Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
if (bundle != null){
//---retrieve the SMS message received---
try{
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]);
msg_from = msgs[i].getOriginatingAddress();
msgBody = msgs[i].getMessageBody();
}
if(msgBody.contains("#earthquake")) {
if(msg_from.contains("+8801553721331"))
Toast.makeText(context, "Earthquake Alert!", Toast.LENGTH_SHORT).show();
intent = new Intent(context, DialogActivity.class);
intent.putExtra("smsbody", msgBody);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}catch(Exception e){
Log.d("Exception caught",e.getMessage());
}
}
}
//throw new UnsupportedOperationException("Not yet implemented");
}
}
view raw SmsListener.java hosted with ❤ by GitHub
A
Anindya Das Antar
NASA Logo

SpaceApps is a NASA incubator innovation program.