Search in sources :

Example 11 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class CursorUtils method prepareEmulator.

public static void prepareEmulator(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (Integer.parseInt(telephonyManager.getDeviceId()) > 0)
        return;
    try {
        context.getContentResolver().delete(Uri.parse("content://sms/"), null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    ContentResolver contentResolver = context.getContentResolver();
    String[][] messages = new String[][] { // address, body, date, type
    { "4165254009", "Why are you texting myself?", "1399856640", "" + Message.RECEIVED }, { "4166485592", "These popups are so handy!", "1400079840", "" + Message.RECEIVED } };
    for (int i = 0; i < messages.length; i++) {
        ContentValues cv = new ContentValues();
        cv.put("address", messages[i][0]);
        cv.put("body", messages[i][1]);
        cv.put("date", messages[i][2]);
        cv.put("date_sent", messages[i][2]);
        cv.put("type", messages[i][3]);
        contentResolver.insert(SmsHelper.SMS_CONTENT_PROVIDER, cv);
    }
/*for (int i = 0; i < messages.length; i++) {
            ContentValues cv = new ContentValues();
            cv.put("date", messages[i][2]);
            contentResolver.update(SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, cv, "snippit=" + messages[i][1], null);
        }*/
}
Also used : ContentValues(android.content.ContentValues) TelephonyManager(android.telephony.TelephonyManager) ContentResolver(android.content.ContentResolver)

Example 12 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class DeliveredReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (LOCAL_LOGV)
        Log.v(TAG, "marking message as delivered");
    Uri uri;
    try {
        uri = Uri.parse(intent.getStringExtra("message_uri"));
        if (uri.equals("")) {
            uri = null;
        }
    } catch (Exception e) {
        uri = null;
    }
    switch(getResultCode()) {
        case Activity.RESULT_OK:
            // notify user that message was delivered
            Intent delivered = new Intent(Transaction.NOTIFY_OF_DELIVERY);
            delivered.putExtra("result", true);
            delivered.putExtra("message_uri", uri == null ? "" : uri.toString());
            context.sendBroadcast(delivered);
            if (uri != null) {
                ContentValues values = new ContentValues();
                values.put("status", "0");
                values.put("date_sent", Calendar.getInstance().getTimeInMillis());
                values.put("read", true);
                context.getContentResolver().update(uri, values, null, null);
            } else {
                Cursor query = context.getContentResolver().query(Uri.parse("content://sms/sent"), null, null, null, "date desc");
                // mark message as delivered in database
                if (query.moveToFirst()) {
                    String id = query.getString(query.getColumnIndex("_id"));
                    ContentValues values = new ContentValues();
                    values.put("status", "0");
                    values.put("date_sent", Calendar.getInstance().getTimeInMillis());
                    values.put("read", true);
                    context.getContentResolver().update(Uri.parse("content://sms/sent"), values, "_id=" + id, null);
                }
                query.close();
            }
            break;
        case Activity.RESULT_CANCELED:
            // notify user that message failed to be delivered
            Intent notDelivered = new Intent(Transaction.NOTIFY_OF_DELIVERY);
            notDelivered.putExtra("result", false);
            notDelivered.putExtra("message_uri", uri == null ? "" : uri.toString());
            context.sendBroadcast(notDelivered);
            if (uri != null) {
                ContentValues values = new ContentValues();
                values.put("status", "64");
                values.put("date_sent", Calendar.getInstance().getTimeInMillis());
                values.put("read", true);
                values.put("error_code", getResultCode());
                context.getContentResolver().update(uri, values, null, null);
            } else {
                Cursor query2 = context.getContentResolver().query(Uri.parse("content://sms/sent"), null, null, null, "date desc");
                // mark failed in database
                if (query2.moveToFirst()) {
                    String id = query2.getString(query2.getColumnIndex("_id"));
                    ContentValues values = new ContentValues();
                    values.put("status", "64");
                    values.put("read", true);
                    values.put("error_code", getResultCode());
                    context.getContentResolver().update(Uri.parse("content://sms/sent"), values, "_id=" + id, null);
                }
                query2.close();
            }
            break;
    }
    context.sendBroadcast(new Intent("com.moez.QKSMS.send_message.REFRESH"));
}
Also used : ContentValues(android.content.ContentValues) Intent(android.content.Intent) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 13 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class SentReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (LOCAL_LOGV)
        Log.v(TAG, "marking message as sent");
    Uri uri;
    try {
        uri = Uri.parse(intent.getStringExtra("message_uri"));
        if (uri.equals("")) {
            uri = null;
        }
    } catch (Exception e) {
        uri = null;
    }
    switch(getResultCode()) {
        case Activity.RESULT_OK:
            if (uri != null) {
                try {
                    if (LOCAL_LOGV)
                        Log.v(TAG, "using supplied uri");
                    ContentValues values = new ContentValues();
                    values.put("type", 2);
                    values.put("read", 1);
                    context.getContentResolver().update(uri, values, null, null);
                } catch (NullPointerException e) {
                    markFirstAsSent(context);
                }
            } else {
                markFirstAsSent(context);
            }
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
        case SmsManager.RESULT_ERROR_NO_SERVICE:
        case SmsManager.RESULT_ERROR_NULL_PDU:
        case SmsManager.RESULT_ERROR_RADIO_OFF:
            if (uri != null) {
                if (LOCAL_LOGV)
                    Log.v(TAG, "using supplied uri");
                ContentValues values = new ContentValues();
                values.put("type", 5);
                values.put("read", true);
                values.put("error_code", getResultCode());
                context.getContentResolver().update(uri, values, null, null);
            } else {
                if (LOCAL_LOGV)
                    Log.v(TAG, "using first message");
                Cursor query = context.getContentResolver().query(Uri.parse("content://sms/outbox"), null, null, null, null);
                // mark message failed
                if (query != null && query.moveToFirst()) {
                    String id = query.getString(query.getColumnIndex("_id"));
                    ContentValues values = new ContentValues();
                    values.put("type", 5);
                    values.put("read", 1);
                    values.put("error_code", getResultCode());
                    context.getContentResolver().update(Uri.parse("content://sms/outbox"), values, "_id=" + id, null);
                }
            }
            context.sendBroadcast(new Intent(Transaction.NOTIFY_SMS_FAILURE));
            break;
    }
    context.sendBroadcast(new Intent("com.moez.QKSMS.send_message.REFRESH"));
}
Also used : ContentValues(android.content.ContentValues) Intent(android.content.Intent) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 14 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class SentReceiver method markFirstAsSent.

private void markFirstAsSent(Context context) {
    if (LOCAL_LOGV)
        Log.v(TAG, "using first message");
    Cursor query = context.getContentResolver().query(Uri.parse("content://sms/outbox"), null, null, null, null);
    // mark message as sent successfully
    if (query != null && query.moveToFirst()) {
        String id = query.getString(query.getColumnIndex("_id"));
        ContentValues values = new ContentValues();
        values.put("type", 2);
        values.put("read", 1);
        context.getContentResolver().update(Uri.parse("content://sms/outbox"), values, "_id=" + id, null);
    }
    query.close();
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor)

Example 15 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class Transaction method createAddr.

// add address to the request
private static Uri createAddr(Context context, String id, String addr) throws Exception {
    ContentValues addrValues = new ContentValues();
    addrValues.put("address", addr);
    addrValues.put("charset", "106");
    // TO
    addrValues.put("type", 151);
    Uri addrUri = Uri.parse("content://mms/" + id + "/addr");
    Uri res = context.getContentResolver().insert(addrUri, addrValues);
    return res;
}
Also used : ContentValues(android.content.ContentValues) Uri(android.net.Uri)

Aggregations

ContentValues (android.content.ContentValues)4022 Cursor (android.database.Cursor)721 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)163 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)55 SQLiteException (android.database.sqlite.SQLiteException)53