List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
/** * Indicate that the current song should be marked as 'liked'. * @return Whether the like was successful. should return false when nothing playing or unknown song and artist *///from www .ja va 2s .co m public boolean like() { if (LOCAL_LOGV) log("like()", "v"); boolean success = false; if (isSongDisliked()) { this.undislike(); } if (!isSongLiked()) { if (this.isSongValidForOpinion()) { Uri uri = ContentProviderRadio.CONTENT_URI_LIKES; ContentValues values = new ContentValues(); values.put(DbContractRadio.EntryLike.COLUMN_NAME_ARTIST, mArtist.trim()); values.put(DbContractRadio.EntryLike.COLUMN_NAME_SONG, mSong.trim()); values.put(DbContractRadio.EntryLike.COLUMN_NAME_STATION_TITLE, mTitle.trim()); values.put(DbContractRadio.EntryLike.COLUMN_NAME_STATION_URL, mUrl.trim()); Uri insertedUri = getContentResolver().insert(uri, values); long id = ContentUris.parseId(insertedUri); if (id > 0) { if (LOCAL_LOGV) log("like success", "v"); success = true; this.updateDetails(); } } } else { //already liked if (LOCAL_LOGV) log("already liked", "v"); success = true; } return success; }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
/** * Indicate that the current song should be marked as 'disliked'. * @return Whether the dislike was successful. should return false when nothing playing or unknown song and artist *///w w w .j ava 2 s.co m public boolean dislike() { if (LOCAL_LOGV) log("dislike()", "v"); boolean success = false; if (isSongLiked()) { this.unlike(); } if (!isSongDisliked()) { //blank song and artist if (this.isSongValidForOpinion()) { Uri uri = ContentProviderRadio.CONTENT_URI_DISLIKES; ContentValues values = new ContentValues(); values.put(DbContractRadio.EntryDislike.COLUMN_NAME_ARTIST, mArtist); values.put(DbContractRadio.EntryDislike.COLUMN_NAME_SONG, mSong); values.put(DbContractRadio.EntryDislike.COLUMN_NAME_STATION_TITLE, mTitle); values.put(DbContractRadio.EntryDislike.COLUMN_NAME_STATION_URL, mUrl); Uri insertedUri = getContentResolver().insert(uri, values); long id = ContentUris.parseId(insertedUri); if (id > 0) { if (LOCAL_LOGV) log("dislike success", "v"); success = true; this.updateDetails(); } } } else { //already disliked if (LOCAL_LOGV) log("already disliked", "v"); success = true; } if (success && SKIP_DISLIKES) { nextPreset(); } return success; }
From source file:com.android.mms.ui.MessageUtils.java
public static Uri saveBitmapAsPart(Context context, Uri messageUri, Bitmap bitmap) throws MmsException { ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, IMAGE_COMPRESSION_QUALITY, os); PduPart part = new PduPart(); part.setContentType("image/jpeg".getBytes()); String contentId = "Image" + System.currentTimeMillis(); part.setContentLocation((contentId + ".jpg").getBytes()); part.setContentId(contentId.getBytes()); part.setData(os.toByteArray());/* ww w . j a v a 2s .c o m*/ Uri retVal = PduPersister.getPduPersister(context).persistPart(part, ContentUris.parseId(messageUri), null); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("saveBitmapAsPart: persisted part with uri=" + retVal); } return retVal; }
From source file:com.android.messaging.mmslib.pdu.PduPersister.java
/** * Move a PDU object from one location to another. * * @param from Specify the PDU object to be moved. * @param to The destination location, should be one of the following: * "content://mms/inbox", "content://mms/sent", * "content://mms/drafts", "content://mms/outbox", * "content://mms/trash"./*w w w . jav a 2s .com*/ * @return New Uri of the moved PDU. * @throws MmsException Error occurred while moving the message. */ public Uri move(final Uri from, final Uri to) throws MmsException { // Check whether the 'msgId' has been assigned a valid value. final long msgId = ContentUris.parseId(from); if (msgId == -1L) { throw new MmsException("Error! ID of the message: -1."); } // Get corresponding int value of destination box. final Integer msgBox = MESSAGE_BOX_MAP.get(to); if (msgBox == null) { throw new MmsException("Bad destination, must be one of " + "content://mms/inbox, content://mms/sent, " + "content://mms/drafts, content://mms/outbox, " + "content://mms/temp."); } final ContentValues values = new ContentValues(1); values.put(Mms.MESSAGE_BOX, msgBox); SqliteWrapper.update(mContext, mContentResolver, from, values, null, null); return ContentUris.withAppendedId(to, msgId); }
From source file:com.android.tv.MainActivity.java
private boolean handleIntent(Intent intent) { // Reset the closed caption settings when the activity is 1)created or 2) restarted. // And do not reset while TvView is playing. if (!mTvView.isPlaying()) { mCaptionSettings = new CaptionSettings(this); }//from w w w .ja va 2 s . c o m // Handle the passed key press, if any. Note that only the key codes that are currently // handled in the TV app will be handled via Intent. // TODO: Consider defining a separate intent filter as passing data of mime type // vnd.android.cursor.item/channel isn't really necessary here. int keyCode = intent.getIntExtra(Utils.EXTRA_KEY_KEYCODE, KeyEvent.KEYCODE_UNKNOWN); if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (DEBUG) Log.d(TAG, "Got an intent with keycode: " + keyCode); KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, keyCode); onKeyUp(keyCode, event); return true; } mShouldTuneToTunerChannel = intent.getBooleanExtra(Utils.EXTRA_KEY_FROM_LAUNCHER, false); mInitChannelUri = null; String extraAction = intent.getStringExtra(Utils.EXTRA_KEY_ACTION); if (!TextUtils.isEmpty(extraAction)) { if (DEBUG) Log.d(TAG, "Got an extra action: " + extraAction); if (Utils.EXTRA_ACTION_SHOW_TV_INPUT.equals(extraAction)) { String lastWatchedChannelUri = Utils.getLastWatchedChannelUri(this); if (lastWatchedChannelUri != null) { mInitChannelUri = Uri.parse(lastWatchedChannelUri); } mShowSelectInputView = true; } } if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) { mRecordingUri = intent.getParcelableExtra(Utils.EXTRA_KEY_RECORDING_URI); if (mRecordingUri != null) { return true; } } // TODO: remove the checkState once N API is finalized. SoftPreconditions .checkState(TvInputManager.ACTION_SETUP_INPUTS.equals("android.media.tv.action.SETUP_INPUTS")); if (TvInputManager.ACTION_SETUP_INPUTS.equals(intent.getAction())) { runAfterAttachedToWindow(new Runnable() { @Override public void run() { mOverlayManager.showSetupFragment(); } }); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); try { mSource = uri.getQueryParameter(Utils.PARAM_SOURCE); } catch (UnsupportedOperationException e) { // ignore this exception. } // When the URI points to the programs (directory, not an individual item), go to the // program guide. The intention here is to respond to // "content://android.media.tv/program", not "content://android.media.tv/program/XXX". // Later, we might want to add handling of individual programs too. if (Utils.isProgramsUri(uri)) { // The given data is a programs URI. Open the Program Guide. mShowProgramGuide = true; return true; } // In case the channel is given explicitly, use it. mInitChannelUri = uri; if (DEBUG) Log.d(TAG, "ACTION_VIEW with " + mInitChannelUri); if (Channels.CONTENT_URI.equals(mInitChannelUri)) { // Tune to default channel. mInitChannelUri = null; mShouldTuneToTunerChannel = true; return true; } if ((!Utils.isChannelUriForOneChannel(mInitChannelUri) && !Utils.isChannelUriForInput(mInitChannelUri))) { Log.w(TAG, "Malformed channel uri " + mInitChannelUri + " tuning to default instead"); mInitChannelUri = null; return true; } mTuneParams = intent.getExtras(); if (mTuneParams == null) { mTuneParams = new Bundle(); } if (Utils.isChannelUriForTunerInput(mInitChannelUri)) { long channelId = ContentUris.parseId(mInitChannelUri); mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId); } else if (TvContract.isChannelUriForPassthroughInput(mInitChannelUri)) { // If mInitChannelUri is for a passthrough TV input. String inputId = mInitChannelUri.getPathSegments().get(1); TvInputInfo input = mTvInputManagerHelper.getTvInputInfo(inputId); if (input == null) { mInitChannelUri = null; Toast.makeText(this, R.string.msg_no_specific_input, Toast.LENGTH_SHORT).show(); return false; } else if (!input.isPassthroughInput()) { mInitChannelUri = null; Toast.makeText(this, R.string.msg_not_passthrough_input, Toast.LENGTH_SHORT).show(); return false; } } else if (mInitChannelUri != null) { // Handle the URI built by TvContract.buildChannelsUriForInput(). // TODO: Change hard-coded "input" to TvContract.PARAM_INPUT. String inputId = mInitChannelUri.getQueryParameter("input"); long channelId = Utils.getLastWatchedChannelIdForInput(this, inputId); if (channelId == Channel.INVALID_ID) { String[] projection = { Channels._ID }; try (Cursor cursor = getContentResolver().query(uri, projection, null, null, null)) { if (cursor != null && cursor.moveToNext()) { channelId = cursor.getLong(0); } } } if (channelId == Channel.INVALID_ID) { // Couldn't find any channel probably because the input hasn't been set up. // Try to set it up. mInitChannelUri = null; mInputToSetUp = mTvInputManagerHelper.getTvInputInfo(inputId); } else { mInitChannelUri = TvContract.buildChannelUri(channelId); mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId); } } } return true; }
From source file:com.android.tv.MainActivity.java
private void startPip(final boolean fromUserInteraction) { if (mPipChannel == null) { Log.w(TAG, "PIP channel id is an invalid id."); return;/*from ww w.j a v a2 s.c o m*/ } if (DEBUG) Log.d(TAG, "startPip() " + mPipChannel); mPipView.start(mTvInputManagerHelper); boolean success = mPipView.tuneTo(mPipChannel, null, new OnTuneListener() { @Override public void onUnexpectedStop(Channel channel) { Log.w(TAG, "The PIP is Unexpectedly stopped"); enablePipView(false, false); } @Override public void onTuneFailed(Channel channel) { Log.w(TAG, "Fail to start the PIP during channel tuning"); if (fromUserInteraction) { Toast.makeText(MainActivity.this, R.string.msg_no_pip_support, Toast.LENGTH_SHORT).show(); enablePipView(false, false); } } @Override public void onStreamInfoChanged(StreamInfo info) { mTvViewUiManager.updatePipView(); mHandler.removeCallbacks(mRestoreMainViewRunnable); restoreMainTvView(); } @Override public void onChannelRetuned(Uri channel) { if (channel == null) { return; } Channel currentChannel = mChannelDataManager.getChannel(ContentUris.parseId(channel)); if (currentChannel == null) { Log.e(TAG, "onChannelRetuned is called from PIP input but can't find a channel" + " with the URI " + channel); return; } if (isChannelChangeKeyDownReceived()) { // Ignore this message if the user is changing the channel. return; } mPipChannel = currentChannel; mPipView.setCurrentChannel(mPipChannel); } @Override public void onContentBlocked() { updateMediaSession(); } @Override public void onContentAllowed() { updateMediaSession(); } }); if (!success) { Log.w(TAG, "Fail to start the PIP"); return; } if (fromUserInteraction) { checkChannelLockNeeded(mPipView); } // Explicitly make the PIP view main to make the selected input an HDMI-CEC active source. mPipView.setMain(); scheduleRestoreMainTvView(); mTvViewUiManager.onPipStart(); setVolumeByAudioFocusStatus(); }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showDialogAddContact(final String contacto) { final boolean[] agregar = { false }; try {// w ww .j a va 2 s .co m final ContentResolver contentResolver = activity.getContentResolver(); final JSONObject contact = new JSONObject(contacto); String name = null; String phone = null; String selectionArgs = ContactsContract.Contacts.DISPLAY_NAME + " = ? AND " + ContactsContract.CommonDataKinds.Phone.TYPE + "= " + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE; Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, selectionArgs, new String[] { contact.getString("nombre") }, null); if (c.getCount() > 0) { if (c.moveToFirst()) { phone = c.getString(0); } if (phone.equals(contact.getString("telefono"))) { Toast.makeText(activity, "Ya tienes este contacto", Toast.LENGTH_SHORT).show(); } else { LayoutInflater dialogInflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialogView = dialogInflater.inflate(R.layout.add_contact_message, null); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView) .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null) .setNegativeButton(R.string.add_contact_no, null); finderDialog = dialogBuilder.show(); finderDialog.setCanceledOnTouchOutside(true); finderDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { finderDialog.dismiss(); agregar[0] = true; if (agregar[0]) { ContentValues values = new ContentValues(); values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre")); Uri rawContactUri = contentResolver .insert(ContactsContract.RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); long contactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, contact.getString("telefono")); values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); values.put(Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); } } catch (JSONException e) { e.printStackTrace(); } } }); finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); agregar[0] = false; } }); } } else { LayoutInflater dialogInflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialogView = dialogInflater.inflate(R.layout.add_contact_message, null); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView) .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null) .setNegativeButton(R.string.add_contact_no, null); finderDialog = dialogBuilder.show(); finderDialog.setCanceledOnTouchOutside(true); finderDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { finderDialog.dismiss(); agregar[0] = true; if (agregar[0]) { ContentValues values = new ContentValues(); values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre")); Uri rawContactUri = contentResolver .insert(ContactsContract.RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, contact.getString("telefono")); values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); values.put(Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); values.clear(); values.put(Data.MIMETYPE, ContactsContract.Data.CONTENT_TYPE); values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contact.getString("nombre")); values.put(Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); values.clear(); values.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contact.getString("nombre")); values.put(Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); } } catch (JSONException e) { e.printStackTrace(); } } }); finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); agregar[0] = false; } }); } c.close(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showDialogAddContact(final String contacto) { final boolean[] agregar = { false }; try {/*from ww w . j a va 2 s . c om*/ final ContentResolver contentResolver = activity.getContentResolver(); final JSONObject contact = new JSONObject(contacto); String name = null; String phone = null; String selectionArgs = ContactsContract.Contacts.DISPLAY_NAME + " = ? AND " + ContactsContract.CommonDataKinds.Phone.TYPE + "= " + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE; Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, selectionArgs, new String[] { contact.getString("nombre") }, null); if (c.getCount() > 0) { if (c.moveToFirst()) { phone = c.getString(0); } if (phone.equals(contact.getString("telefono"))) { Toast.makeText(activity, "Ya tienes este contacto", Toast.LENGTH_SHORT).show(); } else { LayoutInflater dialogInflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialogView = dialogInflater.inflate(R.layout.add_contact_message, null); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView) .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null) .setNegativeButton(R.string.add_contact_no, null); finderDialog = dialogBuilder.show(); finderDialog.setCanceledOnTouchOutside(true); finderDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { finderDialog.dismiss(); agregar[0] = true; if (agregar[0]) { ContentValues values = new ContentValues(); values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre")); Uri rawContactUri = contentResolver .insert(ContactsContract.RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); long contactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, contact.getString("telefono")); values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); } } catch (JSONException e) { e.printStackTrace(); } } }); finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); agregar[0] = false; } }); } } else { LayoutInflater dialogInflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialogView = dialogInflater.inflate(R.layout.add_contact_message, null); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView) .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null) .setNegativeButton(R.string.add_contact_no, null); finderDialog = dialogBuilder.show(); finderDialog.setCanceledOnTouchOutside(true); finderDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { finderDialog.dismiss(); agregar[0] = true; if (agregar[0]) { ContentValues values = new ContentValues(); values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre")); Uri rawContactUri = contentResolver .insert(ContactsContract.RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, contact.getString("telefono")); values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); values.clear(); values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.Data.CONTENT_TYPE); values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contact.getString("nombre")); values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); values.clear(); values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contact.getString("nombre")); values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId); contentResolver.insert(ContactsContract.Data.CONTENT_URI, values); } } catch (JSONException e) { e.printStackTrace(); } } }); finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); agregar[0] = false; } }); } c.close(); } catch (JSONException e) { e.printStackTrace(); } }