Search in sources :

Example 1 with Builder

use of csacre15.ipl.be.myapp.Builder in project Synthese_2BIN by TheYoungSensei.

the class SMSReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    MyModel mainModel = ((Builder) context.getApplicationContext()).getModel();
    Bundle bundle = intent.getExtras();
    Object[] pdus = (Object[]) bundle.get("pdus");
    SmsMessage[] messages = new SmsMessage[pdus.length];
    String message = "";
    String tel = "";
    for (int i = 0; i < pdus.length; i++) {
        messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        message += messages[i].getMessageBody();
        tel = messages[i].getOriginatingAddress();
    }
    String[] decoded = message.split(";");
    if (decoded[0].equalsIgnoreCase("#laFete")) {
        if (decoded.length != 4) {
            Toast.makeText(context, "Petit Coquin", Toast.LENGTH_LONG).show();
        } else {
            mainModel.ajouterUtil(decoded[1], decoded[2], decoded[3], tel);
        }
    } else {
        Toast.makeText(context, "Petit Coquin", Toast.LENGTH_LONG).show();
    }
}
Also used : SmsMessage(android.telephony.SmsMessage) MyModel(csacre15.ipl.be.myapp.model.MyModel) Bundle(android.os.Bundle) Builder(csacre15.ipl.be.myapp.Builder)

Aggregations

Bundle (android.os.Bundle)1 SmsMessage (android.telephony.SmsMessage)1 Builder (csacre15.ipl.be.myapp.Builder)1 MyModel (csacre15.ipl.be.myapp.model.MyModel)1