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);
}
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;
}
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);
}
Aggregations