Search in sources :

Example 1 with SmsMessage

use of android.telephony.SmsMessage in project cw-omnibus by commonsguy.

the class Monitor method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Object[] rawMsgs = (Object[]) intent.getExtras().get("pdus");
    for (Object raw : rawMsgs) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[]) raw);
        if (msg.getMessageBody().toUpperCase().contains("SEKRIT")) {
            Log.w("SMS:" + msg.getOriginatingAddress(), msg.getMessageBody());
            abortBroadcast();
        }
    }
}
Also used : SmsMessage(android.telephony.SmsMessage)

Example 2 with SmsMessage

use of android.telephony.SmsMessage in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class IntentReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals("android.intent.action.PROVIDER_CHANGED")) {
        if (!MetaWatchService.Preferences.notifyGmail)
            return;
        if (!Utils.isGmailAccessSupported(context)) {
            String recipient = "You";
            Bundle bundle = intent.getExtras();
            if (bundle.containsKey("account"))
                recipient = bundle.getString("account");
            Log.d(MetaWatch.TAG, "count for " + recipient + ": " + bundle.getInt("count"));
            int count = bundle.getInt("count");
            Monitors.updateGmailUnreadCount(recipient, count);
            if (count > 0)
                NotificationBuilder.createGmailBlank(context, recipient);
            else
                Idle.updateLcdIdle(context);
            return;
        }
    }
    if (action.equals("android.provider.Telephony.SMS_RECEIVED")) {
        if (!MetaWatchService.Preferences.notifySMS)
            return;
        Bundle bundle = intent.getExtras();
        if (bundle.containsKey("pdus")) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            SmsMessage[] smsMessage = new SmsMessage[pdus.length];
            for (int i = 0; i < smsMessage.length; i++) {
                smsMessage[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                String number = smsMessage[i].getOriginatingAddress();
                String body = smsMessage[i].getDisplayMessageBody();
                NotificationBuilder.createSMS(context, number, body);
            }
        }
        return;
    }
    if (action.equals("com.fsck.k9.intent.action.EMAIL_RECEIVED")) {
        if (!MetaWatchService.Preferences.notifyK9)
            return;
        Bundle bundle = intent.getExtras();
        String subject = bundle.getString("com.fsck.k9.intent.extra.SUBJECT");
        String sender = bundle.getString("com.fsck.k9.intent.extra.FROM");
        NotificationBuilder.createK9(context, sender, subject);
        return;
    }
    if (action.equals("com.android.alarmclock.ALARM_ALERT") || action.equals("com.htc.android.worldclock.ALARM_ALERT") || action.equals("com.android.deskclock.ALARM_ALERT") || action.equals("com.sonyericsson.alarm.ALARM_ALERT")) {
        if (!MetaWatchService.Preferences.notifyAlarm)
            return;
        NotificationBuilder.createAlarm(context);
        return;
    }
    if (intent.getAction().equals("com.android.music.metachanged") || intent.getAction().equals("com.htc.music.metachanged")) //if (intent.getAction().equals("com.android.music.metachanged") || intent.getAction().equals("com.htc.music.metachanged") || intent.getAction().equals("com.android.music.playstatechanged") || intent.getAction().equals("com.htc.music.playstatechanged"))  
    {
        if (!MetaWatchService.Preferences.notifyMusic)
            return;
        String artist = "";
        String track = "";
        if (intent.hasExtra("artist"))
            artist = intent.getStringExtra("artist");
        if (intent.hasExtra("track"))
            track = intent.getStringExtra("track");
        NotificationBuilder.createMusic(context, artist, track);
        return;
    }
}
Also used : SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle)

Example 3 with SmsMessage

use of android.telephony.SmsMessage in project Signal-Android by WhisperSystems.

the class SmsListener method isRelevant.

private boolean isRelevant(Context context, Intent intent) {
    SmsMessage message = getSmsMessageFromIntent(intent);
    String messageBody = getSmsMessageBodyFromIntent(intent);
    if (message == null && messageBody == null)
        return false;
    if (isExemption(message, messageBody))
        return false;
    if (!ApplicationMigrationService.isDatabaseImported(context))
        return false;
    if (isChallenge(context, messageBody))
        return false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && SMS_RECEIVED_ACTION.equals(intent.getAction()) && Util.isDefaultSmsProvider(context)) {
        return false;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && TextSecurePreferences.isInterceptAllSmsEnabled(context)) {
        return true;
    }
    return false;
}
Also used : SmsMessage(android.telephony.SmsMessage)

Example 4 with SmsMessage

use of android.telephony.SmsMessage in project qksms by moezbhatti.

the class MessageStatusService method updateMessageStatus.

private SmsMessage updateMessageStatus(Context context, Uri messageUri, byte[] pdu, String format) {
    SmsMessage message = SmsMessage.createFromPdu(pdu);
    if (message == null) {
        return null;
    }
    // Create a "status/#" URL and use it to update the
    // message's status in the database.
    Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), messageUri, ID_PROJECTION, null, null, null);
    try {
        if (cursor.moveToFirst()) {
            int messageId = cursor.getInt(0);
            Uri updateUri = ContentUris.withAppendedId(STATUS_URI, messageId);
            int status = message.getStatus();
            boolean isStatusReport = message.isStatusReportMessage();
            ContentValues contentValues = new ContentValues(2);
            log("updateMessageStatus: msgUrl=" + messageUri + ", status=" + status + ", isStatusReport=" + isStatusReport);
            contentValues.put("status", status);
            contentValues.put("date_sent", System.currentTimeMillis());
            SqliteWrapper.update(context, context.getContentResolver(), updateUri, contentValues, null, null);
        } else {
            error("Can't find message for status update: " + messageUri);
        }
    } finally {
        cursor.close();
    }
    return message;
}
Also used : ContentValues(android.content.ContentValues) SmsMessage(android.telephony.SmsMessage) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 5 with SmsMessage

use of android.telephony.SmsMessage in project qksms by moezbhatti.

the class MessagingReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "onReceive");
    abortBroadcast();
    mContext = context;
    mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (intent.getExtras() != null) {
        Object[] pdus = (Object[]) intent.getExtras().get("pdus");
        SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int i = 0; i < messages.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        }
        SmsMessage sms = messages[0];
        if (messages.length == 1 || sms.isReplace()) {
            mBody = sms.getDisplayMessageBody();
        } else {
            StringBuilder bodyText = new StringBuilder();
            for (SmsMessage message : messages) {
                bodyText.append(message.getMessageBody());
            }
            mBody = bodyText.toString();
        }
        mAddress = sms.getDisplayOriginatingAddress();
        mDate = sms.getTimestampMillis();
        if (mPrefs.getBoolean(SettingsFragment.SHOULD_I_ANSWER, false) && PackageUtils.isAppInstalled(mContext, "org.mistergroup.muzutozvednout")) {
            ShouldIAnswerBinder shouldIAnswerBinder = new ShouldIAnswerBinder();
            shouldIAnswerBinder.setCallback(new ShouldIAnswerBinder.Callback() {

                @Override
                public void onNumberRating(String number, int rating) {
                    Log.i(TAG, "onNumberRating " + number + ": " + String.valueOf(rating));
                    shouldIAnswerBinder.unbind(context.getApplicationContext());
                    if (rating != ShouldIAnswerBinder.RATING_NEGATIVE) {
                        insertMessageAndNotify();
                    }
                }

                @Override
                public void onServiceConnected() {
                    try {
                        shouldIAnswerBinder.getNumberRating(mAddress);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onServiceDisconnected() {
                }
            });
            shouldIAnswerBinder.bind(context.getApplicationContext());
        } else {
            insertMessageAndNotify();
        }
    }
}
Also used : SmsMessage(android.telephony.SmsMessage) ShouldIAnswerBinder(org.mistergroup.muzutozvednout.ShouldIAnswerBinder)

Aggregations

SmsMessage (android.telephony.SmsMessage)17 Bundle (android.os.Bundle)7 ContentValues (android.content.ContentValues)2 Cursor (android.database.Cursor)2 AsyncResult (android.os.AsyncResult)2 AlertDialog (android.app.AlertDialog)1 CanceledException (android.app.PendingIntent.CanceledException)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 SQLException (android.database.SQLException)1 Uri (android.net.Uri)1 PowerManager (android.os.PowerManager)1 CdmaInformationRecords (com.android.internal.telephony.cdma.CdmaInformationRecords)1 Builder (csacre15.ipl.be.myapp.Builder)1 MyModel (csacre15.ipl.be.myapp.model.MyModel)1 DataHandler (fr.neamar.kiss.DataHandler)1 ContactsProvider (fr.neamar.kiss.dataprovider.ContactsProvider)1 ContactsPojo (fr.neamar.kiss.pojo.ContactsPojo)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)1