Search in sources :

Example 1 with ShouldIAnswerBinder

use of org.mistergroup.muzutozvednout.ShouldIAnswerBinder 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)1 ShouldIAnswerBinder (org.mistergroup.muzutozvednout.ShouldIAnswerBinder)1