Android Open Source - ccardstats Sms Receiver






From Project

Back to project page ccardstats.

License

The source code is released under:

GNU General Public License

If you think the Android project ccardstats listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.marwinxxii.ccardstats;
/*from   w  w w. j ava 2 s  . co m*/
import com.github.marwinxxii.ccardstats.db.DBHelper;
import com.github.marwinxxii.ccardstats.gui.CardListActivity;
import com.github.marwinxxii.ccardstats.notifications.SmsNotification;
import com.github.marwinxxii.ccardstats.notifications.SmsParser;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SmsReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        if (bundle == null)
            return;
        Object[] pdus = (Object[]) bundle.get("pdus");
        DBHelper helper = new DBHelper(context);
        String address = null;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < pdus.length; i++) {
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[i]);
            if (address == null) {
                address = sms.getDisplayOriginatingAddress();
            } else if (!address.equals(sms.getDisplayOriginatingAddress())) {
                //error
                return;
            }
            builder.append(sms.getDisplayMessageBody());
        }
        SmsNotification notif = SmsParser.parse(address, builder.toString());
        if (notif != null) {
            helper.saveCard(notif.card, notif.card, notif.balance);
            helper.addNotification(notif);
        }
        CardListActivity.prepareCardsInfo(helper, helper.getCards());
        helper.close();
    }

}




Java Source Code List

com.github.marwinxxii.ccardstats.Application.java
com.github.marwinxxii.ccardstats.SmsReceiver.java
com.github.marwinxxii.ccardstats.db.Card.java
com.github.marwinxxii.ccardstats.db.DBHelper.java
com.github.marwinxxii.ccardstats.gui.CardListActivity.java
com.github.marwinxxii.ccardstats.gui.GetStatsTask.java
com.github.marwinxxii.ccardstats.gui.ListActivity.java
com.github.marwinxxii.ccardstats.gui.MonthStatsActivity.java
com.github.marwinxxii.ccardstats.gui.PreferencesActivity.java
com.github.marwinxxii.ccardstats.gui.SimpleListActivity.java
com.github.marwinxxii.ccardstats.gui.TextMappingAdapter.java
com.github.marwinxxii.ccardstats.gui.YearStatsActivity.java
com.github.marwinxxii.ccardstats.helpers.DateHelper.java
com.github.marwinxxii.ccardstats.helpers.MoneyHelper.java
com.github.marwinxxii.ccardstats.notifications.NotificationReader.java
com.github.marwinxxii.ccardstats.notifications.NotificationService.java
com.github.marwinxxii.ccardstats.notifications.SberbankService.java
com.github.marwinxxii.ccardstats.notifications.SmsNotification.java
com.github.marwinxxii.ccardstats.notifications.SmsParser.java
com.github.marwinxxii.ccardstats.notifications.SmsReader.java