Search in sources :

Example 6 with Message

use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.

the class DeleteUnreadMessageService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Uri threadUri = intent.getParcelableExtra(EXTRA_THREAD_URI);
    // The messages are marked as read before deleting due to an issue with the android content
    // provider. When the message is deleted, it doesn't notify the conversations table. So if
    // there is an unread message, and it's deleted, then the conversation will remain unread.
    // Then even when you try to mark it as read and it iterates over unread messages to mark
    // them read, it won't be able to find any because they were deleted, leaving the
    // conversation "stuck" as unread. The only way to un-stick it is to receive a new message
    // in the conversation and mark that as read. Marking them read before deleting them solves
    // this problem.
    ArrayList<Message> messages = SmsHelper.getUnreadMessagesLegacy(this, threadUri);
    for (Message message : messages) {
        message.markRead();
        message.delete();
    }
    NotificationManager.update(this);
}
Also used : Message(com.moez.QKSMS.data.Message) Uri(android.net.Uri)

Example 7 with Message

use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.

the class SmsHelper method getFailedMessages.

public static List<Message> getFailedMessages(Context context) {
    Cursor cursor = null;
    List<Message> messages = new ArrayList<>();
    try {
        cursor = context.getContentResolver().query(SMS_CONTENT_PROVIDER, new String[] { COLUMN_ID }, FAILED_SELECTION, null, sortDateDesc);
        cursor.moveToFirst();
        for (int i = 0; i < cursor.getCount(); i++) {
            messages.add(new Message(context, cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID))));
            cursor.moveToNext();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return messages;
}
Also used : Message(com.moez.QKSMS.data.Message) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MmsException(com.google.android.mms.MmsException)

Example 8 with Message

use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.

the class NotificationService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Uri uri = Uri.parse(intent.getStringExtra(EXTRA_URI));
    // Try to get the message's ID, in case the given Uri is bad.
    long messageId = -1;
    Cursor cursor = context.getContentResolver().query(uri, new String[] { SmsHelper.COLUMN_ID }, null, null, null);
    if (cursor.moveToFirst()) {
        messageId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsHelper.COLUMN_ID));
    }
    cursor.close();
    // Make sure we found a message before showing QuickReply and using PushBullet.
    if (messageId != -1) {
        Message message = new Message(context, messageId);
        conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
        if (conversationPrefs.getNotificationsEnabled()) {
            // Only show QuickReply if we're outside of the app, and they have popups and QuickReply enabled.
            if (!LifecycleHandler.isApplicationVisible() && intent.getBooleanExtra(EXTRA_POPUP, false) && prefs.getBoolean(SettingsFragment.QUICKREPLY, Build.VERSION.SDK_INT < 24)) {
                popupIntent = new Intent(context, QKReplyActivity.class);
                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                popupIntent.putExtra(QKReplyActivity.EXTRA_THREAD_ID, message.getThreadId());
                startActivity(popupIntent);
            }
            // Get the photo for the PushBullet notification.
            Bitmap photoBitmap = message.getPhotoBitmap();
            if (photoBitmap == null) {
                photoBitmap = ContactHelper.blankContact(context, message.getName());
            }
            PushbulletService.mirrorMessage(context, "" + message.getThreadId(), message.getName(), message.getBody(), photoBitmap, null, 6639);
        } else {
            // If the conversation is muted, mark this message as "seen". Note that this is
            // different from marking it as "read".
            message.markSeen();
        }
    }
    stopSelf();
    return super.onStartCommand(intent, flags, startId);
}
Also used : QKReplyActivity(com.moez.QKSMS.ui.popup.QKReplyActivity) Bitmap(android.graphics.Bitmap) Message(com.moez.QKSMS.data.Message) Intent(android.content.Intent) Cursor(android.database.Cursor) Uri(android.net.Uri) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Aggregations

Message (com.moez.QKSMS.data.Message)8 Cursor (android.database.Cursor)5 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 MmsException (com.google.android.mms.MmsException)3 ConversationPrefsHelper (com.moez.QKSMS.common.ConversationPrefsHelper)3 R.attr.data (android.R.attr.data)1 AlertDialog (android.app.AlertDialog)1 LoaderManager (android.app.LoaderManager)1 ContentResolver (android.content.ContentResolver)1 ContentUris (android.content.ContentUris)1 Context (android.content.Context)1 CursorLoader (android.content.CursorLoader)1 DialogInterface (android.content.DialogInterface)1 Loader (android.content.Loader)1 SQLiteException (android.database.sqlite.SQLiteException)1 SqliteWrapper (android.database.sqlite.SqliteWrapper)1 Bitmap (android.graphics.Bitmap)1 Sensor (android.hardware.Sensor)1