List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:ca.rmen.android.scrumchatter.member.list.Members.java
/** * Renames a member/*from w w w . j av a 2 s . co m*/ */ public void renameMember(final long memberId, final String memberName) { Log.v(TAG, "rename member " + memberId + " to " + memberName); // Rename the member in a background thread Schedulers.io().scheduleDirect(() -> { Uri uri = Uri.withAppendedPath(MemberColumns.CONTENT_URI, String.valueOf(memberId)); ContentValues values = new ContentValues(1); values.put(MemberColumns.NAME, memberName); mActivity.getContentResolver().update(uri, values, null, null); }); }
From source file:org.odk.collect.android.widgets.DrawWidget.java
private void deleteMedia() { // Get the file path and delete the file /*/*from w w w .ja v a 2 s. co m*/ * There's only 1 in this case, but android 1.6 doesn't implement delete on * android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI only on * android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI + a # */ String[] projection = { Images.ImageColumns._ID }; Cursor c = getContext().getContentResolver().query( android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, "_data='" + mInstanceFolder + mBinaryName + "'", null, null); int del = 0; if (c.getCount() > 0) { c.moveToFirst(); String id = c.getString(c.getColumnIndex(Images.ImageColumns._ID)); Log.i(t, "attempting to delete: " + Uri.withAppendedPath(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)); del = getContext().getContentResolver().delete( Uri.withAppendedPath(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id), null, null); } c.close(); // Clean up variables mBinaryName = null; Log.i(t, "Deleted " + del + " rows from media content provider"); }
From source file:net.kourlas.voipms_sms.activities.ConversationQuickReplyActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversation_quick_reply); database = Database.getInstance(getApplicationContext()); preferences = Preferences.getInstance(getApplicationContext()); contact = getIntent().getExtras().getString(getString(R.string.conversation_extra_contact)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w .j av a 2 s. co m*/ ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Integer notificationId = Notifications.getInstance(getApplicationContext()).getNotificationIds() .get(contact); if (notificationId != null) { manager.cancel(notificationId); } TextView replyToText = (TextView) findViewById(R.id.reply_to_edit_text); String contactName = Utils.getContactName(getApplicationContext(), contact); if (contactName == null) { replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " " + Utils.getFormattedPhoneNumber(contact)); } else { replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " " + contactName); } final EditText messageText = (EditText) findViewById(R.id.message_edit_text); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { messageText.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15); } }); messageText.setClipToOutline(true); } messageText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher); if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) { viewSwitcher.setDisplayedChild(0); } else if (viewSwitcher.getDisplayedChild() == 0) { viewSwitcher.setDisplayedChild(1); } } }); QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo); Utils.applyCircularMask(photo); photo.assignContactFromPhone(Preferences.getInstance(getApplicationContext()).getDid(), true); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Preferences.getInstance(getApplicationContext()).getDid())); Cursor cursor = getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToFirst()) { String photoUri = cursor .getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); if (photoUri != null) { photo.setImageURI(Uri.parse(photoUri)); } else { photo.setImageToDefault(); } } else { photo.setImageToDefault(); } cursor.close(); final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button); Utils.applyCircularMask(sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preSendMessage(); } }); Button openAppButton = (Button) findViewById(R.id.open_app_button); openAppButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); Intent intent = new Intent(activity, ConversationActivity.class); intent.putExtra(getString(R.string.conversation_extra_contact), contact); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); stackBuilder.startActivities(); } }); messageText.requestFocus(); }
From source file:com.cyanogenmod.filemanager.util.MediaHelper.java
/** * Method that converts a file reference to a content uri reference * * @param cr A content resolver// w w w . j a va2 s .c o m * @param path The path to search * @param volume The volume * @return Uri The content uri or null if file not exists in the media database */ private static Uri fileToContentUri(ContentResolver cr, String path, String volume) { final String[] projection = { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE }; final String where = MediaColumns.DATA + " = ?"; Uri baseUri = MediaStore.Files.getContentUri(volume); Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null); try { if (c != null && c.moveToNext()) { int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE)); if (type != 0) { // Do not force to use content uri for no media files long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID)); return Uri.withAppendedPath(baseUri, String.valueOf(id)); } } } finally { IOUtils.closeQuietly(c); } return null; }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteImagesInFolderFromMediaProvider(File folder) { ContentResolver cr = Collect.getInstance().getContentResolver(); // images/*from ww w . j av a2 s . c om*/ int count = 0; Cursor imageCursor = null; try { String select = Images.Media.DATA + " like ? escape '!'"; String[] selectArgs = { escapePath(folder.getAbsolutePath()) }; String[] projection = { Images.ImageColumns._ID }; imageCursor = cr.query(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (imageCursor.getCount() > 0) { imageCursor.moveToFirst(); List<Uri> imagesToDelete = new ArrayList<Uri>(); do { String id = imageCursor.getString(imageCursor.getColumnIndex(Images.ImageColumns._ID)); imagesToDelete.add(Uri .withAppendedPath(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)); } while (imageCursor.moveToNext()); for (Uri uri : imagesToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (imageCursor != null) { imageCursor.close(); } } return count; }
From source file:org.trakhound.www.trakhound.device_list.GetDevices.java
public static ListItem[] get(String token) { if (token != null) { String url = Uri.withAppendedPath(ApiConfiguration.apiHost, "data/get/index.php").toString(); PostData[] postDatas = new PostData[3]; postDatas[0] = new PostData("token", token); postDatas[1] = new PostData("sender_id", UserManagement.getSenderId()); postDatas[2] = new PostData("command", "1101"); // Get Description, Status, and Oee tables String response = Requests.post(url, postDatas); return processResponse(response); }/*from www . j a v a 2 s. c o m*/ return null; }
From source file:org.odk.collect.android.tasks.DownloadFormsTask.java
@Override protected HashMap<String, String> doInBackground(ArrayList<FormDetails>... values) { ArrayList<FormDetails> toDownload = values[0]; int total = toDownload.size(); int count = 1; HashMap<String, String> result = new HashMap<String, String>(); for (int i = 0; i < total; i++) { FormDetails fd = toDownload.get(i); publishProgress(fd.formName, Integer.valueOf(count).toString(), Integer.valueOf(total).toString()); String message = ""; try {/* w w w.j a va 2 s . c o m*/ // get the xml file // if we've downloaded a duplicate, this gives us the file File dl = downloadXform(fd.formName, fd.downloadUrl); String[] projection = { FormsColumns._ID, FormsColumns.FORM_FILE_PATH }; String[] selectionArgs = { dl.getAbsolutePath() }; String selection = FormsColumns.FORM_FILE_PATH + "=?"; Cursor alreadyExists = Collect.getInstance().getContentResolver().query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null); Uri uri = null; if (alreadyExists.getCount() <= 0) { // doesn't exist, so insert it ContentValues v = new ContentValues(); v.put(FormsColumns.FORM_FILE_PATH, dl.getAbsolutePath()); HashMap<String, String> formInfo = FileUtils.parseXML(dl); v.put(FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE)); v.put(FormsColumns.MODEL_VERSION, formInfo.get(FileUtils.MODEL)); v.put(FormsColumns.UI_VERSION, formInfo.get(FileUtils.UI)); v.put(FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID)); v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI)); uri = Collect.getInstance().getContentResolver().insert(FormsColumns.CONTENT_URI, v); } else { alreadyExists.moveToFirst(); uri = Uri.withAppendedPath(FormsColumns.CONTENT_URI, alreadyExists.getString(alreadyExists.getColumnIndex(FormsColumns._ID))); } if (fd.manifestUrl != null) { Cursor c = Collect.getInstance().getContentResolver().query(uri, null, null, null, null); if (c.getCount() > 0) { // should be exactly 1 c.moveToFirst(); String error = downloadManifestAndMediaFiles( c.getString(c.getColumnIndex(FormsColumns.FORM_MEDIA_PATH)), fd, count, total); if (error != null) { message += error; } } } else { // TODO: manifest was null? Log.e(t, "Manifest was null. PANIC"); } } catch (SocketTimeoutException se) { se.printStackTrace(); message += se.getMessage(); } catch (Exception e) { e.printStackTrace(); message += e.getMessage(); } count++; if (message.equalsIgnoreCase("")) { message = Collect.getInstance().getString(R.string.success); } result.put(fd.formName, message); } return result; }
From source file:com.openerp.base.res.Res_PartnerSyncHelper.java
public Uri getPartnerUri(int partner_id) { Account account = OpenERPAccountManager.getAccount(mContext, OEUser.current(mContext).getAndroidName()); Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(); mContentResolver = mContext.getContentResolver(); Cursor data = mContentResolver.query(rawContactUri, null, SYNC1_PARTNER_ID + " = " + partner_id, null, null);// w w w . j a va2s .com String contact_raw_id = null; while (data.moveToNext()) { contact_raw_id = data.getString(data.getColumnIndex(ContactsContract.Contacts._ID)); } data.close(); Uri contact_uri = null; if (contact_raw_id != null) { contact_uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contact_raw_id); } return contact_uri; }
From source file:cz.maresmar.sfm.view.menu.portal.PortalMenuFragment.java
@NonNull @Override/*from w w w.j ava 2 s. c om*/ public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) { switch (id) { case DAY_LOADER_ID: { Uri daysUri = Uri.withAppendedPath(mUserUri, ProviderContract.DAY_PATH); return new CursorLoader(getContext(), daysUri, new String[] { ProviderContract.Day._ID, ProviderContract.Day.DATE }, ProviderContract.Day.DATE + " >= " + MenuUtils.getTodayDate(), null, null); } case MENU_LOADER_ID: { Uri menuUri = Uri.withAppendedPath(mUserUri, ProviderContract.MENU_ENTRY_PATH); return new CursorLoader(getContext(), menuUri, MenuViewAdapter.PROJECTION, ProviderContract.MenuEntry.PORTAL_ID + " = " + mPortalId, null, ProviderContract.MenuEntry.DATE + " ASC"); } default: throw new UnsupportedOperationException("Unknown loader id: " + id); } }
From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java
private static void updateContactStatus(ArrayList<ContentProviderOperation> operationList, long rawContactId, String status) {// w ww. j a v a 2 s . c om Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); Cursor c = mContentResolver.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null); try { while (c.moveToNext()) { if (!c.isNull(1)) { String mimeType = c.getString(2); if (mimeType.equals("vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile")) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1)); builder.withValue(ContactsContract.StatusUpdates.STATUS, status); builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "org.c99.SyncProviderDemo"); builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.logo); builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP, System.currentTimeMillis()); operationList.add(builder.build()); //Only change the text of our custom entry to the status message pre-Honeycomb, as the newer contacts app shows //statuses elsewhere if (Integer.decode(Build.VERSION.SDK) < 11) { builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); builder.withSelection(BaseColumns._ID + " = '" + c.getLong(1) + "'", null); builder.withValue(ContactsContract.Data.DATA3, status); operationList.add(builder.build()); } } } } } finally { c.close(); } }