Java Code Examples for android.content.ContentUris#withAppendedId()
The following examples show how to use
android.content.ContentUris#withAppendedId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistentBlobProvider.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private Uri create(@NonNull Context context, @NonNull InputStream input, long id, @NonNull String mimeType, @Nullable String fileName, @Nullable Long fileSize) { persistToDisk(context, id, input); final Uri uniqueUri = CONTENT_URI.buildUpon() .appendPath(mimeType) .appendPath(fileName) .appendEncodedPath(String.valueOf(fileSize)) .appendEncodedPath(String.valueOf(System.currentTimeMillis())) .build(); return ContentUris.withAppendedId(uniqueUri, id); }
Example 2
Source File: LauncherProvider.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
@Override public Uri insert(Uri uri, ContentValues initialValues) { SqlArguments args = new SqlArguments(uri); // In very limited cases, we support system|signature permission apps to modify the db. if (Binder.getCallingPid() != Process.myPid()) { if (!mOpenHelper.initializeExternalAdd(initialValues)) { return null; } } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); addModifiedTime(initialValues); final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues); if (rowId < 0) return null; uri = ContentUris.withAppendedId(uri, rowId); notifyListeners(); if (Utilities.ATLEAST_MARSHMALLOW) { reloadLauncherIfExternal(); } else { // Deprecated behavior to support legacy devices which rely on provider callbacks. LauncherAppState app = LauncherAppState.getInstanceNoCreate(); if (app != null && "true".equals(uri.getQueryParameter("isExternalAdd"))) { app.reloadWorkspace(); } String notify = uri.getQueryParameter("notify"); if (notify == null || "true".equals(notify)) { getContext().getContentResolver().notifyChange(uri, null); } } return uri; }
Example 3
Source File: MediaStoreUtil.java From APlayer with GNU General Public License v3.0 | 5 votes |
/** * 设置铃声 */ public static void setRing(Context context, int audioId) { try { ContentValues cv = new ContentValues(); cv.put(MediaStore.Audio.Media.IS_RINGTONE, true); cv.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); cv.put(MediaStore.Audio.Media.IS_ALARM, false); cv.put(MediaStore.Audio.Media.IS_MUSIC, true); // 把需要设为铃声的歌曲更新铃声库 if (mContext.getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cv, MediaStore.MediaColumns._ID + "=?", new String[]{audioId + ""}) > 0) { Uri newUri = ContentUris .withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioId); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); ToastUtil.show(context, R.string.set_ringtone_success); } else { ToastUtil.show(context, R.string.set_ringtone_error); } } catch (Exception e) { //没有权限 if (e instanceof SecurityException) { ToastUtil.show(context, R.string.please_give_write_settings_permission); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.System.canWrite(mContext)) { Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + mContext.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Util.isIntentAvailable(mContext, intent)) { mContext.startActivity(intent); } } } } } }
Example 4
Source File: StorageUtil.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
private static Uri getContentUriForImageFromMediaStore(Context context, String path) { ContentResolver resolver = context.getContentResolver(); //Uri photoUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // to handle hidden images Uri photoUri = MediaStore.Files.getContentUri("external"); Cursor cursor = resolver.query(photoUri, new String[]{BaseColumns._ID}, MediaStore.MediaColumns.DATA + " = ?", new String[]{path}, null); if (cursor == null) { return Uri.parse(path); } cursor.moveToFirst(); if (cursor.isAfterLast()) { cursor.close(); // insert system media db ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DATA, path); values.put(MediaStore.Images.Media.MIME_TYPE, MediaType.getMimeType(path)); return context.getContentResolver().insert(photoUri, values); } else { long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); Uri uri = ContentUris.withAppendedId(photoUri, id); cursor.close(); return uri; } }
Example 5
Source File: SensorsDataContentProvider.java From sa-sdk-android with Apache License 2.0 | 5 votes |
private Uri insertEvent(Uri uri, ContentValues values) { SQLiteDatabase database; try { database = dbHelper.getWritableDatabase(); } catch (SQLiteException e) { isDbWritable = false; SALog.printStackTrace(e); return uri; } if (!values.containsKey(DbParams.KEY_DATA) || !values.containsKey(DbParams.KEY_CREATED_AT)) { return uri; } long d = database.insert(DbParams.TABLE_EVENTS, "_id", values); return ContentUris.withAppendedId(uri, d); }
Example 6
Source File: PartAuthority.java From Silence with GNU General Public License v3.0 | 4 votes |
public static Uri getAttachmentThumbnailUri(AttachmentId attachmentId) { Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, String.valueOf(attachmentId.getUniqueId())); return ContentUris.withAppendedId(uri, attachmentId.getRowId()); }
Example 7
Source File: CalendarReminderUtils.java From imsdk-android with MIT License | 4 votes |
@SuppressLint("MissingPermission") public static void updateCalendarEvent(Context context, CalendarTrip.DataBean.TripsBean bean, int remindInAdvance, long eventID, long calId){ //添加日历事件 long start = 0; long end = 0; try { start = DateUtil.string2Time(bean.getBeginTime(), "yyyy-MM-dd HH:mm:ss").getTime(); end = DateUtil.string2Time(bean.getEndTime(), "yyyy-MM-dd HH:mm:ss").getTime(); } catch (Exception e) { e.printStackTrace(); } String locan = TextUtils.isEmpty(bean.getAppointment())?bean.getTripLocale()+"-"+bean.getTripRoom():bean.getAppointment(); String der = "会议详情:\n"+bean.getTripIntr(); ContentValues event = new ContentValues(); event.put(CalendarContract.Events.TITLE, bean.getTripName()); String inviterID = QtalkStringUtils.parseId(bean.getTripInviter())+"@" + QtalkNavicationService.getInstance().getEmail(); event.put(CalendarContract.Events.ORGANIZER,inviterID); event.put(CalendarContract.Events.ORIGINAL_SYNC_ID,bean.getTripId()); event.put(CalendarContract.Events.DESCRIPTION,der); event.put(CalendarContract.Events.EVENT_LOCATION,locan); event.put(CalendarContract.Events.CALENDAR_ID, calId); //插入账户的id event.put(CalendarContract.Events.DTSTART, start); event.put(CalendarContract.Events.DTEND, end); event.put(CalendarContract.Events.HAS_ALARM, 1);//设置有闹钟提醒 event.put(CalendarContract.Events.EVENT_TIMEZONE, "Asia/Shanghai");//这个是时区,必须有 Uri updateUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID); int rows = context.getContentResolver().update(updateUri, event, null, null); Logger.i("更新日历数据行数:"+rows); for (int i = 0; i < bean.getMemberList().size(); i++) { // Nick nick = ConnectionUtil.getInstance().getNickById(bean.getMemberList().get(i).getMemberId()); ////// ContentResolver cr = context.getContentResolver(); ////// ContentValues values = new ContentValues(); ////// values.put(CalendarContract.Attendees.ATTENDEE_NAME, nick.getName()); ////// values.put(CalendarContract.Attendees.ATTENDEE_EMAIL, nick.getUserId()+"@qunar.com"); ////// values.put(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP, CalendarContract.Attendees.RELATIONSHIP_ATTENDEE); ////// values.put(CalendarContract.Attendees.ATTENDEE_TYPE, CalendarContract.Attendees.TYPE_OPTIONAL); ////// int status = 0; ////// if(bean.getMemberList().get(i).getMemberState().equals("0")){ ////// status = CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE; ////// }else if(bean.getMemberList().get(i).getMemberState().equals("1")){ ////// status = CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED; ////// }else if(bean.getMemberList().get(i).getMemberState().equals("2")){ ////// status = CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED; ////// } ////// values.put(CalendarContract.Attendees.ATTENDEE_STATUS, status); ////// values.put(CalendarContract.Attendees.EVENT_ID, eventID); ////// ////// ////// ////// Uri uri = ContentUris.withAppendedId(CalendarContract.Attendees.CONTENT_URI,eventID); ////// ////// int s = cr.update(uri,values,null,null); Nick nick = ConnectionUtil.getInstance().getNickById(bean.getMemberList().get(i).getMemberId()); // String name = nick.getName(); // members+=(name+"\n"); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Attendees.ATTENDEE_NAME, nick.getName()); values.put(CalendarContract.Attendees.ATTENDEE_EMAIL, nick.getUserId()+"@" + QtalkNavicationService.getInstance().getEmail()); values.put(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP, CalendarContract.Attendees.RELATIONSHIP_ATTENDEE); values.put(CalendarContract.Attendees.ATTENDEE_TYPE, CalendarContract.Attendees.TYPE_OPTIONAL); int status = 0; if(bean.getMemberList().get(i).getMemberState().equals("0")){ status = CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE; }else if(bean.getMemberList().get(i).getMemberState().equals("1")){ status = CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED; }else if(bean.getMemberList().get(i).getMemberState().equals("2")){ status = CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED; } values.put(CalendarContract.Attendees.ATTENDEE_STATUS, status); values.put(CalendarContract.Attendees.EVENT_ID, eventID); @SuppressLint("MissingPermission") Uri uri = cr.insert(CalendarContract.Attendees.CONTENT_URI, values); // Logger.i("更新联系人状态:"+s); } }
Example 8
Source File: ChatSessionAdapter.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
private void init(Contact contact, boolean isNewSession) { mIsGroupChat = false; mNickname = contact.getName(); ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager(); mContactId = listManager.queryOrInsertContact(contact); mChatURI = ContentUris.withAppendedId(Imps.Chats.CONTENT_URI, mContactId); if (isNewSession) setLastMessage(null); mMessageURI = Imps.Messages.getContentUriByThreadId(mContactId); mContactStatusMap.put(contact.getName(), contact.getPresence().getStatus()); }
Example 9
Source File: ContractData.java From stockita-point-of-sale with MIT License | 4 votes |
public static Uri buildSalesDetailPendingUri(long id) { return ContentUris.withAppendedId(CONTENT_URI, id); }
Example 10
Source File: ImApp.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
public static void deleteAccount (ContentResolver resolver, long accountId, long providerId) { IImConnection conn = getConnection(providerId, accountId); Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId); resolver.delete(accountUri, null, null); Uri providerUri = ContentUris.withAppendedId(Imps.Provider.CONTENT_URI, providerId); resolver.delete(providerUri, null, null); Uri.Builder builder = Imps.Contacts.CONTENT_URI_CONTACTS_BY.buildUpon(); ContentUris.appendId(builder, providerId); ContentUris.appendId(builder, accountId); resolver.delete(builder.build(), null, null); }
Example 11
Source File: MusicUtil.java From MusicPlayer with GNU General Public License v3.0 | 4 votes |
public static Uri getSongFileUri(int songId) { return ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId); }
Example 12
Source File: FilterRulesFragment.java From NekoSMS with GNU General Public License v3.0 | 4 votes |
public void startFilterEditorActivity(long id) { Intent intent = new Intent(getContext(), FilterEditorActivity.class); Uri filterUri = ContentUris.withAppendedId(DatabaseContract.FilterRules.CONTENT_URI, id); intent.setData(filterUri); startActivity(intent); }
Example 13
Source File: LinphoneContact.java From Linphone4Android with GNU General Public License v3.0 | 4 votes |
private Uri getContactPictureUri() { Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(getAndroidId())); return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO); }
Example 14
Source File: HNewsContract.java From yahnac with Apache License 2.0 | 4 votes |
public static Uri buildBookmarksUriWith(long id) { return ContentUris.withAppendedId(CONTENT_BOOKMARKS_URI, id); }
Example 15
Source File: ConnectionEditDialogFragment.java From MongoExplorer with MIT License | 4 votes |
public Loader<Cursor> onCreateLoader(int arg0, Bundle args) { Uri uri = ContentUris.withAppendedId(MongoBrowserProvider.CONNECTION_URI, args.getLong(Constants.ARG_CONNECTION_ID)); return new CursorLoader(getActivity(), uri, null, null, null, null); }
Example 16
Source File: PartAuthority.java From bcm-android with GNU General Public License v3.0 | 4 votes |
public static @NonNull Uri getGroupAttachmentUri(long gid, long rowId) { Uri uri = Uri.withAppendedPath(GROUP_CONTENT_URI, String.valueOf(gid)); return ContentUris.withAppendedId(uri, rowId); }
Example 17
Source File: MusicService.java From Rey-MusicPlayer with Apache License 2.0 | 4 votes |
public Uri getUri(long audioId) { return ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioId); }
Example 18
Source File: MusicUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public static Uri getSongFileUri(int songId) { return ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId); }
Example 19
Source File: OnboardingManager.java From zom-android-matrix with Apache License 2.0 | 2 votes |
public static void addExistingAccount (Activity context, Handler handler, String username, String domain, String password, OnboardingListener onboardingListener) { final OnboardingAccount result = new OnboardingAccount(); int port = 5222; ContentResolver cr = context.getContentResolver(); ImPluginHelper helper = ImPluginHelper.getInstance(context); long providerId = helper.createAdditionalProvider(helper.getProviderNames().get(0)); //xmpp FIXME long accountId = ImApp.insertOrUpdateAccount(cr, providerId, -1, username, username, password); if (accountId == -1) return; Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId); Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[]{Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE}, Imps.ProviderSettings.PROVIDER + "=?", new String[]{Long.toString(providerId)}, null); Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap( pCursor, cr, providerId, false /* don't keep updated */, null /* no handler */); //should check to see if Orbot is installed and running boolean doDnsSrvLookup = true; settings.setRequireTls(true); settings.setTlsCertVerify(true); settings.setAllowPlainAuth(false); settings.setDoDnsSrv(doDnsSrvLookup); String newDeviceId = DEFAULT_DEVICE_NAME + "-" + UUID.randomUUID().toString().substring(0, 8); settings.setDeviceName(newDeviceId); try { settings.setDomain(domain); settings.setPort(port); settings.requery(); result.username = username; result.domain = domain; result.password = password; result.providerId = providerId; result.accountId = accountId; //now keep this account signed-in ContentValues values = new ContentValues(); values.put(Imps.AccountColumns.KEEP_SIGNED_IN, 1); cr.update(accountUri, values, null, null); settings.requery(); if (Looper.myLooper() == null) Looper.prepare(); final MatrixConnection conn = new MatrixConnection(context); conn.initUser(providerId, accountId); conn.checkAccount(accountId, password, providerId, new MatrixConnection.LoginListener() { @Override public void onLoginSuccess() { onboardingListener.registrationSuccessful(result); } @Override public void onLoginFailed(String message) { onboardingListener.registrationFailed(message); } }); // settings closed in registerAccount } catch (Exception e) { LogCleaner.error(LOG_TAG, "error registering new account", e); onboardingListener.registrationFailed(e.getMessage()); } settings.close(); }
Example 20
Source File: DroidTermsExampleContract.java From android-dev-challenge with Apache License 2.0 | 2 votes |
/** * This method creates a {@link Uri} for a single term, referenced by id. * @param id The id of the term. * @return The Uri with the appended id. */ public static Uri buildTermUriWithId(long id) { return ContentUris.withAppendedId(CONTENT_URI, id); }