List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:at.bitfire.ical4android.AndroidEvent.java
protected Uri eventSyncURI() { if (id == null) throw new IllegalStateException("Event doesn't have an ID yet"); return calendar.syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, id)); }
From source file:com.andryr.musicplayer.PlaybackService.java
private void open() { // Intent i = new Intent(META_CHANGED); // sendStickyBroadcast(i); Bundle extras = new Bundle(); extras.putInt(EXTRA_POSITION, getPositionWithinPlayList()); sendBroadcast(POSITION_CHANGED, extras); mMediaPlayer.reset();/*from w ww.ja v a 2 s . c om*/ Uri songUri = ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCurrentSong.getId()); try { mMediaPlayer.setDataSource(getApplicationContext(), songUri); mMediaPlayer.prepareAsync(); } catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) { ACRA.getErrorReporter().handleException(e); Log.e("ee", "ee", e); } }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) { Context context = getContext(); if (context == null) { return null; }/*w w w .j a v a2 s . c om*/ if (values == null) { throw new IllegalArgumentException("Invalid ContentValues: must not be null"); } if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME) || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name: " + values); } // Check to make sure the component name is valid ComponentName componentName = ComponentName .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); } // Make sure they are using the short string format values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString()); // Ensure the app inserting the artwork is either Muzei or the same app as the source String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName) && !TextUtils.equals(callingPackageName, componentName.getPackageName())) { throw new IllegalArgumentException("Calling package name (" + callingPackageName + ") must match the source's package name (" + componentName.getPackageName() + ")"); } if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) { String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); Intent viewIntent; try { if (!TextUtils.isEmpty(viewIntentString)) { // Make sure it is a valid Intent URI viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME); // Make sure we can construct a PendingIntent for the Intent PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); } } catch (URISyntaxException e) { Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } catch (RuntimeException e) { // This is actually meant to catch a FileUriExposedException, but you can't // have catch statements for exceptions that don't exist at your minSdkVersion Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } } // Ensure the related source has been added to the database. // This should be true in 99.9% of cases, but the insert will fail if this isn't true Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { componentName.flattenToShortString() }, null); if (sourceQuery == null || sourceQuery.getCount() == 0) { ContentValues initialValues = new ContentValues(); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues); } if (sourceQuery != null) { sourceQuery.close(); } values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis()); final SQLiteDatabase db = databaseHelper.getWritableDatabase(); long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, values); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the artwork ID pattern and the new row ID appended to it. final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId); File artwork = getCacheFileForArtworkUri(artworkUri); if (artwork != null && artwork.exists()) { // The image already exists so we'll notifyChange() to say the new artwork is ready // Otherwise, this will be called when the file is written with openFile() // using this Uri and the actual artwork is written successfully notifyChange(artworkUri); } return artworkUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
@SuppressLint("NewApi") private String getPath(Context context, Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from www . ja v a 2 s.co m*/ // TODO handle non-primary volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { // Return the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.android.email.EmailNotificationController.java
private static void refreshNotificationsForAccountInternal(final Context context, final long accountId) { final Uri accountUri = EmailProvider.uiUri("uiaccount", accountId); final ContentResolver contentResolver = context.getContentResolver(); final Cursor mailboxCursor = contentResolver.query( ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId), null, null, null, null);// w w w. ja v a 2 s .c o m try { while (mailboxCursor.moveToNext()) { final long mailboxId = mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN); if (mailboxId == 0) continue; final int unseenCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN); final int unreadCount; // If nothing is unseen, clear the notification if (unseenCount == 0) { unreadCount = 0; } else { unreadCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN); } final Uri folderUri = EmailProvider.uiUri("uifolder", mailboxId); LogUtils.d(LOG_TAG, "Changes to account " + accountId + ", folder: " + mailboxId + ", unreadCount: " + unreadCount + ", unseenCount: " + unseenCount); final Intent intent = new Intent(UIProvider.ACTION_UPDATE_NOTIFICATION); intent.setPackage(context.getPackageName()); intent.setType(EmailProvider.EMAIL_APP_MIME_TYPE); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT, accountUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER, folderUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT, unreadCount); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT, unseenCount); context.sendOrderedBroadcast(intent, null); } } finally { mailboxCursor.close(); } }
From source file:at.flack.MainActivity.java
public static final Bitmap fetchThumbnail(Activity context, String number) { Integer id = fetchThumbnailId(context, number); if (id == null) return null; final Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id); final Cursor cursor = context.getContentResolver().query(uri, SMSItem.PHOTO_BITMAP_PROJECTION, null, null, null);/*from ww w. ja v a 2 s. c o m*/ try { Bitmap thumbnail = null; if (cursor.moveToFirst()) { final byte[] thumbnailBytes = cursor.getBlob(0); if (thumbnailBytes != null) { thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length); } } return thumbnail; } finally { cursor.close(); } }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the Box account is changed */ private void updateBoxAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.box_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.box_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsBoxUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); boolean authorized = getBoxProvider().isAccountAuthorized(); TextView acctView = (TextView) findViewById(R.id.box_acct); assert acctView != null; acctView.setText(acct);//from ww w . java 2 s . c o m View freqSpinLabel = findViewById(R.id.box_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.box_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); GuiUtils.setVisible(findViewById(R.id.box_acct_unlink), !authorized); } else { itsBoxUri = null; } }
From source file:com.csipsimple.ui.dialpad.DialerFragment.java
public void placeVMCall() { Long accountToUse = SipProfile.INVALID_ID; SipProfile acc = null;// w w w. j a v a 2 s. com acc = accountChooserButton.getSelectedAccount(); if (acc == null) { // Maybe we could inform user nothing will happen here? return; } accountToUse = acc.id; if (accountToUse >= 0) { SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id, new String[] { SipProfile.FIELD_VOICE_MAIL_NBR }); if (!TextUtils.isEmpty(vmAcc.vm_nbr)) { // Account already have a VM number try { service.makeCall(vmAcc.vm_nbr, (int) acc.id); } catch (RemoteException e) { Log.e(THIS_FILE, "Service can't be called to make the call"); } } else { // Account has no VM number, propose to create one final long editedAccId = acc.id; LayoutInflater factory = LayoutInflater.from(getActivity()); final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null); missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name) .setView(textEntryView) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield); if (tf != null) { String vmNumber = tf.getText().toString(); if (!TextUtils.isEmpty(vmNumber)) { ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber); int updated = getActivity().getContentResolver() .update(ContentUris.withAppendedId( SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null, null); Log.d(THIS_FILE, "Updated accounts " + updated); } } missingVoicemailDialog.hide(); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { missingVoicemailDialog.hide(); } } }).create(); // When the dialog is up, completely hide the in-call UI // underneath (which is in a partially-constructed state). missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); missingVoicemailDialog.show(); } } else if (accountToUse == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(), (new ComponentName(getActivity(), com.csipsimple.plugins.telephony.CallHandler.class) .flattenToString()))) { // Case gsm voice mail TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); String vmNumber = tm.getVoiceMailNumber(); if (!TextUtils.isEmpty(vmNumber)) { if (service != null) { try { service.ignoreNextOutgoingCallFor(vmNumber); } catch (RemoteException e) { Log.e(THIS_FILE, "Not possible to ignore next"); } } Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm) .setMessage(R.string.no_voice_mail_configured) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { missingVoicemailDialog.hide(); } } }).create(); // When the dialog is up, completely hide the in-call UI // underneath (which is in a partially-constructed state). missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); missingVoicemailDialog.show(); } } // TODO : manage others ?... for now, no way to do so cause no vm stored }
From source file:com.indeema.email.NotificationController.java
private static void refreshNotificationsForAccountInternal(final Context context, final long accountId) { final ContentResolver contentResolver = context.getContentResolver(); final Cursor accountCursor = contentResolver.query(EmailProvider.uiUri("uiaccount", accountId), UIProvider.ACCOUNTS_PROJECTION, null, null, null); if (accountCursor == null) { LogUtils.e(LOG_TAG, "Null account cursor for account id %d", accountId); return;/*w w w . j a v a 2s.c o m*/ } com.indeema.mail.providers.Account account = null; try { if (accountCursor.moveToFirst()) { account = new com.indeema.mail.providers.Account(accountCursor); } } finally { accountCursor.close(); } if (account == null) { LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account %d", accountId); return; } final Cursor mailboxCursor = contentResolver.query( ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId), null, null, null, null); try { while (mailboxCursor.moveToNext()) { final long mailboxId = mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN); if (mailboxId == 0) continue; final int unreadCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN); final int unseenCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN); final Cursor folderCursor = contentResolver.query(EmailProvider.uiUri("uifolder", mailboxId), UIProvider.FOLDERS_PROJECTION, null, null, null); if (folderCursor == null) { LogUtils.e(LOG_TAG, "Null folder cursor for account %d, mailbox %d", accountId, mailboxId); continue; } Folder folder = null; try { if (folderCursor.moveToFirst()) { folder = new Folder(folderCursor); } else { LogUtils.e(LOG_TAG, "Empty folder cursor for account %d, mailbox %d", accountId, mailboxId); continue; } } finally { folderCursor.close(); } LogUtils.d(LOG_TAG, "Changes to account " + account.name + ", folder: " + folder.name + ", unreadCount: " + unreadCount + ", unseenCount: " + unseenCount); NotificationUtils.setNewEmailIndicator(context, unreadCount, unseenCount, account, folder, true); } } finally { mailboxCursor.close(); } }
From source file:com.android.email.NotificationController.java
private static void refreshNotificationsForAccountInternal(final Context context, final long accountId) { final ContentResolver contentResolver = context.getContentResolver(); final Cursor accountCursor = contentResolver.query(EmailProvider.uiUri("uiaccount", accountId), UIProvider.ACCOUNTS_PROJECTION, null, null, null); if (accountCursor == null) { LogUtils.e(LOG_TAG, "Null account cursor for account id %d", accountId); return;/* w ww. ja v a 2 s.co m*/ } com.android.mail.providers.Account account = null; try { if (accountCursor.moveToFirst()) { account = new com.android.mail.providers.Account(accountCursor); } } finally { accountCursor.close(); } if (account == null) { LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account %d", accountId); return; } final Cursor mailboxCursor = contentResolver.query( ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId), null, null, null, null); try { while (mailboxCursor.moveToNext()) { final long mailboxId = mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN); if (mailboxId == 0) continue; final int unreadCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN); final int unseenCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN); final Cursor folderCursor = contentResolver.query(EmailProvider.uiUri("uifolder", mailboxId), UIProvider.FOLDERS_PROJECTION, null, null, null); if (folderCursor == null) { LogUtils.e(LOG_TAG, "Null folder cursor for account %d, mailbox %d", accountId, mailboxId); continue; } Folder folder = null; try { if (folderCursor.moveToFirst()) { folder = new Folder(folderCursor); } else { LogUtils.e(LOG_TAG, "Empty folder cursor for account %d, mailbox %d", accountId, mailboxId); continue; } } finally { folderCursor.close(); } LogUtils.d(LOG_TAG, "Changes to account " + account.name + ", folder: " + folder.name + ", unreadCount: " + unreadCount + ", unseenCount: " + unseenCount); NotificationUtils.setNewEmailIndicator(context, unreadCount, unseenCount, account, folder, true); } } finally { mailboxCursor.close(); } }