Search in sources :

Example 1 with SMS

use of dev.sagar.smsblocker.tech.beans.SMS in project SMSBlocker by sagarpawardev.

the class LocalSMSSentReceiver method onReceive.

/**
 * This method is called by Android when SMS is Received
 * @param context Context
 * @param intent SMSReceived Intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    final String methodName = "onReceive()";
    log.justEntered(methodName);
    String action = intent.getAction();
    Bundle basket = intent.getExtras();
    String jsonSMS = basket.getString(KEY_SMS);
    SMS sms = gson.fromJson(jsonSMS, SMS.class);
    String msg = null;
    switch(action) {
        case SMSSentReceiver.KEY_SMS_SENT:
            sms.setType(SMS.TYPE_SENT);
            msg = context.getString(R.string.txt_sms_sent);
            callback.onSMSSent(sms);
            break;
        case SMSSentReceiver.KEY_GENERIC_FAILURE:
            sms.setType(SMS.TYPE_FAILED);
            msg = context.getString(R.string.err_generic_failure);
            callback.onSMSSentFailure(sms);
            break;
        case SMSSentReceiver.KEY_NO_SERVICE:
            sms.setType(SMS.TYPE_FAILED);
            msg = context.getString(R.string.err_no_service);
            callback.onSMSSentFailure(sms);
            break;
        case SMSSentReceiver.KEY_RADIO_OFF:
            msg = context.getString(R.string.err_radio_off);
            sms.setType(SMS.TYPE_FAILED);
            callback.onSMSSentFailure(sms);
            break;
        case SMSSentReceiver.KEY_NULL_PDU_FLAG:
            msg = context.getString(R.string.err_null_pdu);
            sms.setType(SMS.TYPE_FAILED);
            callback.onSMSSentFailure(sms);
            break;
    }
    if (msg != null) {
        log.info(methodName, "Toasting text: " + msg);
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
    log.returning(methodName);
}
Also used : Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS)

Example 2 with SMS

use of dev.sagar.smsblocker.tech.beans.SMS in project SMSBlocker by sagarpawardev.

the class SMSDeliveredReceiver method resultOk.

private void resultOk(Context context, Intent intent) {
    final String methodName = "resultOk(Context, Intent)";
    log.justEntered(methodName);
    Bundle basket = intent.getExtras();
    SMS sms = (SMS) basket.getSerializable(KEY_SMS);
    log.info(methodName, "Broadcasting Locally");
    broadcastLocalSMS(context, sms, KEY_SMS_DELIVERED);
}
Also used : Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS)

Example 3 with SMS

use of dev.sagar.smsblocker.tech.beans.SMS in project SMSBlocker by sagarpawardev.

the class SMSSentReceiver method resultFailure.

private void resultFailure(Context context, Intent intent, String resultCode) {
    final String methodName = "resultOk(Context, Intent)";
    log.justEntered(methodName);
    try {
        Bundle basket = intent.getExtras();
        log.debug(methodName, "Sgr Receiving key: " + KEY_SMS);
        String strSMS = basket.getString(KEY_SMS);
        SMS sms = gson.fromJson(strSMS, SMS.class);
        String id = sms.getId();
        String selection = _id + " = ?";
        String[] selectionArgs = { id };
        ContentValues values = new ContentValues();
        values.put(type, SMS.TYPE_FAILED);
        int updateCount = context.getContentResolver().update(SMS_URI, values, selection, selectionArgs);
        log.info(methodName, "Update Count: " + updateCount);
        log.info(methodName, "Broadcasting Locally");
        broadcastLocalSMS(context, sms, resultCode);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    log.returning(methodName);
}
Also used : ContentValues(android.content.ContentValues) Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS)

Example 4 with SMS

use of dev.sagar.smsblocker.tech.beans.SMS in project SMSBlocker by sagarpawardev.

the class LocalSMSDeliveredReceiver method onReceive.

/**
 * This method is called by Android when SMS is Received
 * @param context
 * @param intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    final String methodName = "onReceive()";
    log.justEntered(methodName);
    Bundle basket = intent.getExtras();
    String jsonSMS = basket.getString(KEY_SMS);
    SMS sms = gson.fromJson(jsonSMS, SMS.class);
    String action = intent.getAction();
    String msg = null;
    switch(action) {
        case SMSDeliveredReceiver.KEY_SMS_DELIVERED:
            msg = context.getString(R.string.txt_delivered);
            log.info(methodName, "Calling Callback");
            callback.onSMSDelivered(sms);
            break;
        case SMSDeliveredReceiver.KEY_DELIVERY_CANCELLED:
            msg = context.getString(R.string.err_delivery_cancelled);
            break;
    }
    if (msg != null) {
        log.info(methodName, "Toasting text: " + msg);
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
    log.returning(methodName);
}
Also used : Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS)

Example 5 with SMS

use of dev.sagar.smsblocker.tech.beans.SMS in project SMSBlocker by sagarpawardev.

the class LocalSMSReceivedReceiver method onReceive.

/**
 * This method is called by Android when SMS is Received
 * @param context
 * @param intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    final String methodName = "onReceive()";
    log.justEntered(methodName);
    // Receive SMS
    if (intent.getAction().equals(EVENT_RECEIVED)) {
        Bundle bundle = intent.getExtras();
        String jsonSMS = bundle.getString(KEY_SMS);
        SMS sms = gson.fromJson(jsonSMS, SMS.class);
        log.info(methodName, "Calling Callback");
        callback.onSMSReceived(sms);
    }
    log.returning(methodName);
}
Also used : Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS)

Aggregations

SMS (dev.sagar.smsblocker.tech.beans.SMS)27 Bundle (android.os.Bundle)11 ContentResolver (android.content.ContentResolver)5 Uri (android.net.Uri)5 ArrayList (java.util.ArrayList)5 Cursor (android.database.Cursor)4 ContentValues (android.content.ContentValues)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 DBHelper (dev.sagar.smsblocker.tech.service.helper.DBHelper)3 HashSet (java.util.HashSet)2 Animator (android.animation.Animator)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)1 Typeface (android.graphics.Typeface)1 Handler (android.os.Handler)1 SmsManager (android.telephony.SmsManager)1 SmsMessage (android.telephony.SmsMessage)1