dimanche 3 juillet 2016

Compare SMS to Database value

I might be completely on the wrong path with what I have got so far.

When a message is received my app successfully plays some music. I'm wanting the app to only play the music when the received text message has a key word in it. As the keywords are changeable, I am trying to compare the body of the text in the message with a value which is stored in the DB.

  @Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        String msg_from;
        String DBRing = myDB.getRing().getString(1);


        if(SmsMessage = DBRing) { //If text message is ring
            MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound);
            mediaPlayer.start(); 
        }

I have done an if statement which will determine whether the text contains the key words but comparing it to the DB value is difficult.

As I say I think i'm on the right lines but I could be way off.

How do I compare the text from a received message with the data which is stored in the database?

Aucun commentaire:

Enregistrer un commentaire