List of usage examples for android.provider BaseColumns _ID
String _ID
To view the source code for android.provider BaseColumns _ID.
Click Source Link
From source file:com.android.mail.compose.ComposeActivity.java
private void runSendOrSaveProviderCalls(SendOrSaveMessage sendOrSaveMessage, SendOrSaveCallback callback, ReplyFromAccount currReplyFromAccount, ReplyFromAccount originalReplyFromAccount) { long messageId = callback.getMessageId(); // If a previous draft has been saved, in an account that is different // than what the user wants to send from, remove the old draft, and treat this // as a new message if (originalReplyFromAccount != null && !currReplyFromAccount.account.uri.equals(originalReplyFromAccount.account.uri)) { if (messageId != UIProvider.INVALID_MESSAGE_ID) { ContentResolver resolver = getContentResolver(); ContentValues values = new ContentValues(); values.put(BaseColumns._ID, messageId); if (originalReplyFromAccount.account.expungeMessageUri != null) { new ContentProviderTask.UpdateTask().run(resolver, originalReplyFromAccount.account.expungeMessageUri, values, null, null); } else { // TODO(mindyp) delete the conversation. }/* www . j a v a 2 s.c om*/ // reset messageId to 0, so a new message will be created messageId = UIProvider.INVALID_MESSAGE_ID; } } final long messageIdToSave = messageId; sendOrSaveMessage(callback, messageIdToSave, sendOrSaveMessage, currReplyFromAccount); if (!sendOrSaveMessage.mSave) { incrementRecipientsTimesContacted((String) sendOrSaveMessage.mValues.get(UIProvider.MessageColumns.TO), (String) sendOrSaveMessage.mValues.get(UIProvider.MessageColumns.CC), (String) sendOrSaveMessage.mValues.get(UIProvider.MessageColumns.BCC)); } callback.sendOrSaveFinished(sendOrSaveMessage, true); }
From source file:com.android.mail.compose.ComposeActivity.java
/** * Send or Save a message./*w w w.jav a 2s . co m*/ */ private void sendOrSaveMessage(SendOrSaveCallback callback, final long messageIdToSave, final SendOrSaveMessage sendOrSaveMessage, final ReplyFromAccount selectedAccount) { final ContentResolver resolver = getContentResolver(); final boolean updateExistingMessage = messageIdToSave != UIProvider.INVALID_MESSAGE_ID; final String accountMethod = sendOrSaveMessage.mSave ? UIProvider.AccountCallMethods.SAVE_MESSAGE : UIProvider.AccountCallMethods.SEND_MESSAGE; try { if (updateExistingMessage) { sendOrSaveMessage.mValues.put(BaseColumns._ID, messageIdToSave); callAccountSendSaveMethod(resolver, selectedAccount.account, accountMethod, sendOrSaveMessage); } else { Uri messageUri = null; final Bundle result = callAccountSendSaveMethod(resolver, selectedAccount.account, accountMethod, sendOrSaveMessage); if (result != null) { // If a non-null value was returned, then the provider handled the call // method messageUri = result.getParcelable(UIProvider.MessageColumns.URI); } if (sendOrSaveMessage.mSave && messageUri != null) { final Cursor messageCursor = resolver.query(messageUri, UIProvider.MESSAGE_PROJECTION, null, null, null); if (messageCursor != null) { try { if (messageCursor.moveToFirst()) { // Broadcast notification that a new message has // been allocated callback.notifyMessageIdAllocated(sendOrSaveMessage, new Message(messageCursor)); } } finally { messageCursor.close(); } } } } } finally { // Close any opened file descriptors closeOpenedAttachmentFds(sendOrSaveMessage); } }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
/** * Read out the mms parts and update the bMessage object provided i {@linkplain message} * @param id the content provider ID of the message * @param message the bMessage object to add the information to *//*from w ww . j ava 2s .c o m*/ private void extractMmsParts(long id, BluetoothMapbMessageMmsEmail message) { /* TODO: If the attachment appParam is set to "no", only add the text parts. * (content type contains "text" - case insensitive) */ final String[] projection = null; String selection = new String("mid=" + id); String uriStr = String.format("content://mms/%d/part", id); Uri uriAddress = Uri.parse(uriStr); BluetoothMapbMessageMmsEmail.MimePart part; Cursor c = mResolver.query(uriAddress, projection, selection, null, null); if (c != null && c.moveToFirst()) { do { Long partId = c.getLong(c.getColumnIndex(BaseColumns._ID)); String contentType = c.getString(c.getColumnIndex("ct")); String name = c.getString(c.getColumnIndex("name")); String charset = c.getString(c.getColumnIndex("chset")); String filename = c.getString(c.getColumnIndex("fn")); String text = c.getString(c.getColumnIndex("text")); Integer fd = c.getInt(c.getColumnIndex("_data")); String cid = c.getString(c.getColumnIndex("cid")); String cl = c.getString(c.getColumnIndex("cl")); String cdisp = c.getString(c.getColumnIndex("cd")); if (D) Log.d(TAG, " _id : " + partId + "\n ct : " + contentType + "\n partname : " + name + "\n charset : " + charset + "\n filename : " + filename + "\n text : " + text + "\n fd : " + fd + "\n cid : " + cid + "\n cl : " + cl + "\n cdisp : " + cdisp); part = message.addMimePart(); part.contentType = contentType; part.partName = name; part.contentId = cid; part.contentLocation = cl; part.contentDisposition = cdisp; try { if (text != null) { part.data = text.getBytes("UTF-8"); part.charsetName = "utf-8"; } else { part.data = readMmsDataPart(partId); if (charset != null) part.charsetName = CharacterSets.getMimeName(Integer.parseInt(charset)); } } catch (NumberFormatException e) { Log.d(TAG, "extractMmsParts", e); part.data = null; part.charsetName = null; } catch (UnsupportedEncodingException e) { Log.d(TAG, "extractMmsParts", e); part.data = null; part.charsetName = null; } finally { } part.fileName = filename; } while (c.moveToNext()); c.close(); } message.updateCharset(); }
From source file:com.android.mail.compose.ComposeActivity.java
/** * Effectively discard the current message. * * This method is either invoked from the menu or from the dialog * once the user has confirmed that they want to discard the message. *///from ww w .j a v a 2s .co m private void doDiscardWithoutConfirmation() { synchronized (mDraftLock) { if (mDraftId != UIProvider.INVALID_MESSAGE_ID) { ContentValues values = new ContentValues(); values.put(BaseColumns._ID, mDraftId); if (!mAccount.expungeMessageUri.equals(Uri.EMPTY)) { getContentResolver().update(mAccount.expungeMessageUri, values, null, null); } else { getContentResolver().delete(mDraft.uri, null, null); } // This is not strictly necessary (since we should not try to // save the draft after calling this) but it ensures that if we // do save again for some reason we make a new draft rather than // trying to resave an expunged draft. mDraftId = UIProvider.INVALID_MESSAGE_ID; } } // Display a toast to let the user know Toast.makeText(this, R.string.message_discarded, Toast.LENGTH_SHORT).show(); // This prevents the draft from being saved in onPause(). discardChanges(); mPerformedSendOrDiscard = true; finish(); }
From source file:com.tct.mail.compose.ComposeActivity.java
protected void sendOrSave(final boolean save, final boolean showToast) { // Check if user is a monkey. Monkeys can compose and hit send // button but are not allowed to send anything off the device. // TS: xiaolin.li 2015-01-08 EMAIL BUGFIX-893877 DEL_S /*if (ActivityManager.isUserAMonkey()) { return;//w ww . j av a2s . c om }*/ // TS: xiaolin.li 2015-01-08 EMAIL BUGFIX-893877 DEL_E final SendOrSaveCallback callback = new SendOrSaveCallback() { // FIXME: unused private int mRestoredRequestId; @Override public void initializeSendOrSave(SendOrSaveTask sendOrSaveTask) { synchronized (mActiveTasks) { int numTasks = mActiveTasks.size(); if (numTasks == 0) { // Start service so we won't be killed if this app is // put in the background. startService(new Intent(ComposeActivity.this, EmptyService.class)); } mActiveTasks.add(sendOrSaveTask); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.initializeSendOrSave(sendOrSaveTask); } } @Override public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) { synchronized (mDraftLock) { mDraftAccount = sendOrSaveMessage.mAccount; mDraftId = message.id; mDraft = message; if (sRequestMessageIdMap != null) { sRequestMessageIdMap.put(sendOrSaveMessage.requestId(), mDraftId); } // Cache request message map, in case the process is killed saveRequestMap(); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message); } } @Override public Message getMessage() { synchronized (mDraftLock) { return mDraft; } } @Override public void sendOrSaveFinished(SendOrSaveTask task, boolean success) { // Update the last sent from account. if (mAccount != null) { MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString()); } // TS: zhaotianyong 2015-03-25 EMAIL BUGFIX-954496 ADD_S // TS: zhaotianyong 2015-03-31 EMAIL BUGFIX-963249 ADD_S if (doSend) { ConnectivityManager mConnectivityManager = (ConnectivityManager) ComposeActivity.this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); if (info == null) { Utility.showToast(ComposeActivity.this, R.string.send_failed); } } // TS: zhaotianyong 2015-03-31 EMAIL BUGFIX-963249 ADD_E // TS: zhaotianyong 2015-03-25 EMAIL BUGFIX-954496 ADD_E if (success) { // Successfully sent or saved so reset change markers discardChanges(); //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 ADD_S if (!doSend && showToast) { Intent intent = new Intent(DRAFT_SAVED_ACTION); intent.setPackage(getString(R.string.email_package_name)); intent.putExtra(BaseColumns._ID, mDraftId); //send ordered broadcast to execute the event in sequence in different receivers, //ordered by priority sendOrderedBroadcast(intent, null); } //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 ADD_E } else { // A failure happened with saving/sending the draft // TODO(pwestbro): add a better string that should be used // when failing to send or save //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083 Utility.showShortToast(ComposeActivity.this, R.string.send_failed); //Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT) // .show(); } int numTasks; synchronized (mActiveTasks) { // Remove the task from the list of active tasks mActiveTasks.remove(task); numTasks = mActiveTasks.size(); } if (numTasks == 0) { // Stop service so we can be killed. stopService(new Intent(ComposeActivity.this, EmptyService.class)); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.sendOrSaveFinished(task, success); } } @Override public void incrementRecipientsTimesContacted(final List<String> recipients) { ComposeActivity.this.incrementRecipientsTimesContacted(recipients); } }; //TS: zheng.zou 2015-3-16 EMAIL BUGFIX_948927 Mod_S if (mReplyFromAccount == null && mAccount != null) { mReplyFromAccount = getDefaultReplyFromAccount(mAccount); } if (mReplyFromAccount != null) { setAccount(mReplyFromAccount.account); } //TS: zheng.zou 2015-3-16 EMAIL BUGFIX_948927 Mod_E // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_S mIsSaveDraft = save; // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_E final Spanned body = removeComposingSpans(mBodyView.getText()); SEND_SAVE_TASK_HANDLER.post(new Runnable() { @Override public void run() { final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body); // TS: kaifeng.lu 2016-4-6 EMAIL BUGFIX_1909143 ADD_S if (/*!mIsClickIcon &&*/ !mEditDraft && (mIsSaveDraft || doSend)) {//[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,05/06/2016,2013535 String body1 = mBodyView.getText().toString().replace("\n", "\n\r"); SpannableString spannableString = new SpannableString(body1); StringBuffer bodySignature = new StringBuffer(body1); //[BUGFIX]-DEL begin by SCDTABLET.shujing.jin@tcl.com,05/17/2016,2013535,2148647 //if(mCachedSettings != null){ // bodySignature.append(convertToPrintableSignature(mCachedSettings.signature)); //} //[BUGFIX]-DEL end by SCDTABLET.shujing.jin spannableString = new SpannableString(bodySignature.toString()); msg.bodyHtml = spannedBodyToHtml(spannableString, true); msg.bodyText = bodySignature.toString(); } // TS: kaifeng.lu 2016-4-6 EMAIL BUGFIX_1909143 ADD_E mRequestId = sendOrSaveInternal(ComposeActivity.this, mReplyFromAccount, msg, mRefMessage, mQuotedTextView.getQuotedTextIfIncluded(), callback, SEND_SAVE_TASK_HANDLER, save, mComposeMode, mDraftAccount, mExtraValues); } }); // Don't display the toast if the user is just changing the orientation, // but we still need to save the draft to the cursor because this is how we restore // the attachments when the configuration change completes. if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { //TS: xinlei.sheng 2015-01-26 EMAIL FIXBUG_886976 MOD_S if (mLaunchContact) { mLaunchContact = false; } else { //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 MDD_S if (!save) { //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083 Utility.showToast(this, R.string.sending_message); //Toast.makeText(this, R.string.sending_message, // Toast.LENGTH_LONG).show(); } // Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message, // Toast.LENGTH_LONG).show(); //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 MOD_E } //TS: xinlei.sheng 2015-01-26 EMAIL FIXBUG_886976 MOD_E } // Need to update variables here because the send or save completes // asynchronously even though the toast shows right away. discardChanges(); updateSaveUi(); // If we are sending, finish the activity if (!save) { finish(); //TS: yanhua.chen 2015-6-15 EMAIL BUGFIX_1024081 ADD_S //TS: lin-zhou 2015-10-15 EMAIL BUGFIX_718388 MOD_S Uri soundUri = Uri.parse( "android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.email_sent); MediaPlayer player = new MediaPlayer(); try { if (soundUri != null) { player.setDataSource(getApplicationContext(), soundUri); } player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); player.prepare(); player.start(); } catch (IllegalArgumentException e) { LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IllegalArgumentException"); } catch (SecurityException e) { LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur SecurityException"); } catch (IllegalStateException e) { LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IllegalStateException"); } catch (IOException e) { LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IOException"); } catch (NullPointerException e) { LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur NullPointerException"); } //TS: lin-zhou 2015-10-15 EMAIL BUGFIX_718388 MOD_E //TS: yanhua.chen 2015-6-15 EMAIL BUGFIX_1024081 ADD_E } }
From source file:com.tct.mail.compose.ComposeActivity.java
/** * Effectively discard the current message. * * This method is either invoked from the menu or from the dialog * once the user has confirmed that they want to discard the message. *///from www . j a va 2 s .c om private void doDiscardWithoutConfirmation() { synchronized (mDraftLock) { if (mDraftId != UIProvider.INVALID_MESSAGE_ID) { ContentValues values = new ContentValues(); values.put(BaseColumns._ID, mDraftId); if (!mAccount.expungeMessageUri.equals(Uri.EMPTY)) { getContentResolver().update(mAccount.expungeMessageUri, values, null, null); } else { getContentResolver().delete(mDraft.uri, null, null); } // This is not strictly necessary (since we should not try to // save the draft after calling this) but it ensures that if we // do save again for some reason we make a new draft rather than // trying to resave an expunged draft. mDraftId = UIProvider.INVALID_MESSAGE_ID; } } // Display a toast to let the user know //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083 Utility.showShortToast(this, R.string.message_discarded); //Toast.makeText(this, R.string.message_discarded, Toast.LENGTH_SHORT).show(); // This prevents the draft from being saved in onPause(). discardChanges(); mPerformedSendOrDiscard = true; finish(); }