mercredi 24 février 2016

Android SQLite and Threads

I have an application that I made that is supposed to read a call and then send a message automatically to the caller. I had created the message programmatically but I decided to let the user create the message for himself in the database. Now I saved the message in the database and can actually view it using toast. But the problem is the message is not being sent as message now. I think the problem is on loading data from the database during the call. Hence I would like to ask if anyone knows a thread I can use to make this work asynchronously Please help me...

Here is the relevant code

NotificationsDatabaseAdapter simsHelper;

case TelephonyManager.CALL_STATE_RINGING:
      final String S1 = "kingmaker";
        String notificationText = simsHelper.getData(S1);

        try {


            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(toPhoneNumber, null, notificationText,
                    null, null);
            Toast.makeText(getApplicationContext(), "SMS sent.",
                    Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Sending SMS failed.",
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

Aucun commentaire:

Enregistrer un commentaire