List of usage examples for android.database.sqlite SqliteWrapper delete
@UnsupportedAppUsage public static int delete(Context context, ContentResolver resolver, Uri uri, String where, String[] selectionArgs)
From source file:com.android.mms.ui.MailBoxMessageContent.java
private void resendShortMessage(long threadId, Uri uri) { Cursor cursor = SqliteWrapper.query(this, getContentResolver(), uri, new String[] { Sms.ADDRESS, Sms.BODY, Sms.SUBSCRIPTION_ID }, null, null, null); if (cursor != null) { try {/*from w ww . j a v a 2 s. com*/ if (cursor.moveToFirst()) { MessageSender sender = new SmsMessageSender(this, new String[] { cursor.getString(SMS_ADDRESS_INDEX) }, cursor.getString(SMS_BODY_INDEX), threadId, cursor.getInt(SMS_SUB_ID_INDEX)); sender.sendMessage(threadId); // Delete the undelivered message since the sender will // save a new one into database. SqliteWrapper.delete(this, getContentResolver(), uri, null, null); } } catch (MmsException e) { Log.e(TAG, e.getMessage()); } finally { cursor.close(); } } else { Toast.makeText(MailBoxMessageContent.this, R.string.send_failure, Toast.LENGTH_SHORT).show(); } }
From source file:com.android.mms.transaction.NotificationTransaction.java
public int checkPduResult() { if (!mPduFile.exists()) { Log.e(MmsApp.TXN_TAG, "checkPduResult MMS Fail, no pduFile = " + mPduFile); return SmsManager.MMS_ERROR_UNSPECIFIED; }/* w w w . j a va2 s . co m*/ FileChannel channel = null; FileInputStream fs = null; RetrieveConf retrieveConf; try { fs = new FileInputStream(mPduFile); channel = fs.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size()); while ((channel.read(byteBuffer)) > 0) { // do nothing // System.out.println("reading"); } final GenericPdu pdu = (new PduParser(byteBuffer.array(), PduParserUtil.shouldParseContentDisposition(mSubId))).parse(); if (pdu == null || !(pdu instanceof RetrieveConf)) { Log.e(MmsApp.TXN_TAG, "checkPduResult: invalid parsed PDU"); return SmsManager.MMS_ERROR_UNSPECIFIED; } retrieveConf = (RetrieveConf) pdu; // Store the downloaded message PduPersister persister = PduPersister.getPduPersister(mContext); Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (messageUri == null) { Log.e(MmsApp.TXN_TAG, "checkPduResult: can not persist message"); return SmsManager.MMS_ERROR_UNSPECIFIED; } mMessageUri = messageUri.toString(); // Update some of the properties of the message final ContentValues values = new ContentValues(); values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L); values.put(Telephony.Mms.READ, 0); values.put(Telephony.Mms.SEEN, 0); String creator = ActivityThread.currentPackageName(); if (!TextUtils.isEmpty(creator)) { values.put(Telephony.Mms.CREATOR, creator); } values.put(Telephony.Mms.SUBSCRIPTION_ID, mSubId); if (SqliteWrapper.update(mContext, mContext.getContentResolver(), messageUri, values, null/*where*/, null/*selectionArg*/) != 1) { Log.e(MmsApp.TXN_TAG, "persistIfRequired: can not update message"); } // Delete the corresponding NotificationInd SqliteWrapper.delete(mContext, mContext.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), mContentLocation }); return Activity.RESULT_OK; } catch (IOException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (MmsException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (SQLiteException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (RuntimeException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } finally { if (mPduFile != null) { mPduFile.delete(); } try { if (channel != null) { channel.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (fs != null) { fs.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.android.mms.ui.MessageListItem.java
private void bindNotifInd() { showMmsView(false);//from w w w .j a v a2 s .c o m mBodyTextView.setText(formatMessage(mMessageItem, null, mMessageItem.mSubject, mMessageItem.mHighlight, mMessageItem.mTextContentType)); mDateView.setText(buildTimestampLine(mMessageItem.mTimestamp)); final String msgSizeText = mContext.getString(R.string.message_size_label) + String.valueOf((mMessageItem.mMessageSize + 1023) / 1024) + mContext.getString(R.string.kilobyte); mMessageSizeView.setText(msgSizeText); mMessageSizeView.setVisibility(View.VISIBLE); updateSimIndicatorView(mMessageItem.mSubId); switch (mMessageItem.getMmsDownloadStatus()) { case DownloadManager.STATE_PRE_DOWNLOADING: case DownloadManager.STATE_DOWNLOADING: showDownloadingAttachment(); break; case DownloadManager.STATE_UNKNOWN: case DownloadManager.STATE_UNSTARTED: DownloadManager downloadManager = DownloadManager.getInstance(); boolean autoDownload = downloadManager.isAuto(); boolean dataSuspended = (MmsApp.getApplication().getTelephonyManager() .getDataState() == TelephonyManager.DATA_SUSPENDED); // If we're going to automatically start downloading the mms attachment, then // don't bother showing the download button for an instant before the actual // download begins. Instead, show downloading as taking place. if (autoDownload && !dataSuspended) { showDownloadingAttachment(); break; } case DownloadManager.STATE_TRANSIENT_FAILURE: case DownloadManager.STATE_PERMANENT_FAILURE: default: setLongClickable(true); inflateDownloadControls(); mDownloading.setVisibility(View.GONE); mDownloadButton.setVisibility(View.VISIBLE); mDownloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mDownloading.setVisibility(View.VISIBLE); try { NotificationInd nInd = (NotificationInd) PduPersister.getPduPersister(mContext) .load(mMessageItem.mMessageUri); Log.d(TAG, "Download notify Uri = " + mMessageItem.mMessageUri); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.download); builder.setCancelable(true); // Judge notification weather is expired if (nInd.getExpiry() < System.currentTimeMillis() / 1000L) { // builder.setIcon(R.drawable.ic_dialog_alert_holo_light); builder.setMessage(mContext.getString(R.string.service_message_not_found)); builder.show(); SqliteWrapper.delete(mContext, mContext.getContentResolver(), mMessageItem.mMessageUri, null, null); return; } // Judge whether memory is full else if (MessageUtils.isMmsMemoryFull()) { builder.setMessage(mContext.getString(R.string.sms_full_body)); builder.show(); return; } // Judge whether message size is too large else if ((int) nInd.getMessageSize() > MmsConfig.getMaxMessageSize()) { builder.setMessage(mContext.getString(R.string.mms_too_large)); builder.show(); return; } } catch (MmsException e) { Log.e(TAG, e.getMessage(), e); return; } mDownloadButton.setVisibility(View.GONE); Intent intent = new Intent(mContext, TransactionService.class); intent.putExtra(TransactionBundle.URI, mMessageItem.mMessageUri.toString()); intent.putExtra(TransactionBundle.TRANSACTION_TYPE, Transaction.RETRIEVE_TRANSACTION); intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mMessageItem.mSubId); mContext.startService(intent); DownloadManager.getInstance().markState(mMessageItem.mMessageUri, DownloadManager.STATE_PRE_DOWNLOADING); } }); break; } // Hide the indicators. mLockedIndicator.setVisibility(View.GONE); mDeliveredIndicator.setVisibility(View.GONE); mDetailsIndicator.setVisibility(View.GONE); updateAvatarView(mMessageItem.mAddress, false); }
From source file:com.android.mms.transaction.RetrieveTransaction.java
public int checkPduResult() { if (!mPduFile.exists()) { Log.e(MmsApp.TXN_TAG, "checkPduResult MMS Fail, no pduFile = " + mPduFile); return SmsManager.MMS_ERROR_UNSPECIFIED; }/*from w w w . ja v a 2 s .co m*/ FileChannel channel = null; FileInputStream fs = null; RetrieveConf retrieveConf; try { fs = new FileInputStream(mPduFile); channel = fs.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size()); while ((channel.read(byteBuffer)) > 0) { // do nothing // System.out.println("reading"); } final GenericPdu pdu = (new PduParser(byteBuffer.array(), PduParserUtil.shouldParseContentDisposition(mSubId))).parse(); if (pdu == null || !(pdu instanceof RetrieveConf)) { Log.e(MmsApp.TXN_TAG, "checkPduResult: invalid parsed PDU"); return SmsManager.MMS_ERROR_UNSPECIFIED; } retrieveConf = (RetrieveConf) pdu; byte[] messageId = retrieveConf.getMessageId(); MmsLog.d(MmsApp.TXN_TAG, "checkPduResult retrieveConf.messageId = " + new String(messageId)); // Store the downloaded message PduPersister persister = PduPersister.getPduPersister(mContext); Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true/*createThreadId*/, true/*groupMmsEnabled*/, null/*preOpenedFiles*/); if (messageUri == null) { Log.e(MmsApp.TXN_TAG, "checkPduResult: can not persist message"); return SmsManager.MMS_ERROR_UNSPECIFIED; } mMessageUri = messageUri.toString(); // Update some of the properties of the message final ContentValues values = new ContentValues(); values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L); values.put(Telephony.Mms.READ, 0); values.put(Telephony.Mms.SEEN, 0); String creator = ActivityThread.currentPackageName(); if (!TextUtils.isEmpty(creator)) { values.put(Telephony.Mms.CREATOR, creator); } values.put(Telephony.Mms.SUBSCRIPTION_ID, mSubId); if (SqliteWrapper.update(mContext, mContext.getContentResolver(), messageUri, values, null/*where*/, null/*selectionArg*/) != 1) { Log.e(MmsApp.TXN_TAG, "persistIfRequired: can not update message"); } // Delete the corresponding NotificationInd SqliteWrapper.delete(mContext, mContext.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), mContentLocation }); return Activity.RESULT_OK; } catch (IOException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (MmsException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (SQLiteException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } catch (RuntimeException e) { e.printStackTrace(); return SmsManager.MMS_ERROR_UNSPECIFIED; } finally { if (mPduFile != null) { mPduFile.delete(); } try { if (channel != null) { channel.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (fs != null) { fs.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void editSmsMessageItem(MessageItem msgItem) { // When the message being edited is the only message in the conversation, the delete // below does something subtle. The trigger "delete_obsolete_threads_pdu" sees that a // thread contains no messages and silently deletes the thread. Meanwhile, the mConversation // object still holds onto the old thread_id and code thinks there's a backing thread in // the DB when it really has been deleted. Here we try and notice that situation and // clear out the thread_id. Later on, when Conversation.ensureThreadId() is called, we'll // create a new thread if necessary. synchronized (mConversation) { if (mConversation.getMessageCount() <= 1) { mConversation.clearThreadId(); MessagingNotification.setCurrentlyDisplayedThreadId(MessagingNotification.THREAD_NONE); }/*from w w w.j ava2 s . co m*/ } // Delete the old undelivered SMS and load its content. Uri uri = ContentUris.withAppendedId(Sms.CONTENT_URI, msgItem.mMsgId); SqliteWrapper.delete(ComposeMessageActivity.this, mContentResolver, uri, null, null); mWorkingMessage.setText(msgItem.mBody); }
From source file:com.android.mms.ui.MessageUtils.java
public static void confirmDeleteMessage(final Activity activity, final Uri msgUri) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.confirm_dialog_title); builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setCancelable(true);/*from ww w. j a va 2 s .co m*/ builder.setMessage(R.string.confirm_delete_message); builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { /// M: fix bug ALPS00351620; for requery searchactivity. SearchActivity.setNeedRequery(); SqliteWrapper.delete(activity.getApplicationContext(), activity.getContentResolver(), msgUri, null, null); dialog.dismiss(); activity.finish(); } }); builder.setNegativeButton(R.string.no, null); builder.show(); }