List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteAudioFileFromMediaProvider(String audioFile) { ContentResolver cr = Collect.getInstance().getContentResolver(); // audio//from w w w.j a v a2 s . co m int count = 0; Cursor audioCursor = null; try { String select = Audio.Media.DATA + "=?"; String[] selectArgs = { audioFile }; String[] projection = { Audio.AudioColumns._ID }; audioCursor = cr.query(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (audioCursor.getCount() > 0) { audioCursor.moveToFirst(); List<Uri> audioToDelete = new ArrayList<Uri>(); do { String id = audioCursor.getString(audioCursor.getColumnIndex(Audio.AudioColumns._ID)); audioToDelete.add( Uri.withAppendedPath(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)); } while (audioCursor.moveToNext()); for (Uri uri : audioToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (audioCursor != null) { audioCursor.close(); } } File f = new File(audioFile); if (f.exists()) { f.delete(); } return count; }
From source file:com.appjma.appdeployer.AppsFragment.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor c = (Cursor) parent.getItemAtPosition(position); String appId = c.getString(AppsAdapter.PROJECTION_APP_ID); startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(AppContract.Apps.CONTENT_URI, appId))); }
From source file:io.github.carlorodriguez.alarmon.MediaListView.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { setItemChecked(position, true);/* w w w .j a v a2 s . co m*/ cursor.moveToPosition(position); selectedName = cursor.getString(cursor.getColumnIndex(nameColumn)); final int toneIndex = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID)); if (toneIndex == DEFAULT_TONE_INDEX) { selectedUri = AlarmUtil.getDefaultAlarmUri(); } else { selectedUri = Uri.withAppendedPath(contentUri, "" + toneIndex); } if (listener != null) { listener.onItemPick(selectedUri, selectedName); } }
From source file:cx.ring.model.Conference.java
public Intent getViewIntent(Context ctx) { final Uri conf_uri = Uri.withAppendedPath(CONTENT_URI, getId()); return new Intent(Intent.ACTION_VIEW).setData(conf_uri).setClass(ctx, CallActivity.class); }
From source file:cx.ring.fragments.CallFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case R.id.menuitem_chat: Intent intent = new Intent().setClass(getActivity(), ConversationActivity.class) .setAction(Intent.ACTION_VIEW).setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, getConference().getParticipants().get(0).getContact().getIds().get(0))); intent.putExtra("resuming", true); startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION); break;/*from w w w. j a v a2s . c om*/ case R.id.menuitem_addcontact: startActivityForResult(getConference().getParticipants().get(0).getContact().getAddNumberIntent(), ConversationActivity.REQ_ADD_CONTACT); break; case R.id.menuitem_speaker: audioManager.setSpeakerphoneOn(!audioManager.isSpeakerphoneOn()); getActivity().invalidateOptionsMenu(); break; } return true; }
From source file:com.oliversride.wordryo.Utils.java
public static String phoneToContact(Context context, String phone, boolean phoneStandsIn) { // I'm assuming that since context is passed this needn't // worry about synchronization -- will always be called from // UI thread. String name;// w ww . j av a 2s . c o m synchronized (s_phonesHash) { if (s_phonesHash.containsKey(phone)) { name = s_phonesHash.get(phone); } else { name = null; ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query( Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToNext()) { int indx = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); name = cursor.getString(indx); } cursor.close(); s_phonesHash.put(phone, name); } } if (null == name && phoneStandsIn) { name = phone; } return name; }
From source file:gov.wa.wsdot.android.wsdot.ui.TravelTimesFragment.java
public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = { TravelTimes._ID, TravelTimes.TRAVEL_TIMES_ID, TravelTimes.TRAVEL_TIMES_TITLE, TravelTimes.TRAVEL_TIMES_UPDATED, TravelTimes.TRAVEL_TIMES_DISTANCE, TravelTimes.TRAVEL_TIMES_AVERAGE, TravelTimes.TRAVEL_TIMES_CURRENT, TravelTimes.TRAVEL_TIMES_IS_STARRED }; Uri baseUri;/*from w w w. j av a 2 s .c om*/ if (mFilter != null) { baseUri = Uri.withAppendedPath(TravelTimes.CONTENT_FILTER_URI, Uri.encode(mFilter)); } else { baseUri = TravelTimes.CONTENT_URI; } CursorLoader cursorLoader = new TravelTimesItemsLoader(getActivity(), baseUri, projection, null, null, null); return cursorLoader; }
From source file:de.schildbach.wallet.ui.monitor.BlockListFragment.java
@Override public void onBlockMenuClick(final View view, final Sha256Hash blockHash) { final PopupMenu popupMenu = new PopupMenu(activity, view); popupMenu.inflate(R.menu.blocks_context); popupMenu.getMenu().findItem(R.id.blocks_context_browse).setVisible(Constants.ENABLE_BROWSE); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override//from w w w. j a v a2 s . c o m public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.blocks_context_browse: final Uri blockExplorerUri = config.getBlockExplorer(); log.info("Viewing block {} on {}", blockHash, blockExplorerUri); startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "block/" + blockHash))); return true; } return false; } }); popupMenu.show(); }
From source file:org.odk.collect.android.upload.AutoSendWorker.java
/** * If the app-level auto-send setting is enabled, send all finalized forms that don't specify not * to auto-send at the form level. If the app-level auto-send setting is disabled, send all * finalized forms that specify to send at the form level. * * Fails immediately if:/*ww w.j ava 2s. c o m*/ * - storage isn't ready * - the network type that toggled on is not the desired type AND no form specifies auto-send * * If the network type doesn't match the auto-send settings, retry next time a connection is * available. */ @NonNull @Override @SuppressLint("WrongThread") public Result doWork() { ConnectivityManager manager = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo currentNetworkInfo = manager.getActiveNetworkInfo(); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !(networkTypeMatchesAutoSendSetting(currentNetworkInfo) || atLeastOneFormSpecifiesAutoSend())) { if (!networkTypeMatchesAutoSendSetting(currentNetworkInfo)) { return Result.RETRY; } return Result.FAILURE; } List<Instance> toUpload = getInstancesToAutoSend(GeneralSharedPreferences.isAutoSendEnabled()); if (toUpload.isEmpty()) { return Result.SUCCESS; } GeneralSharedPreferences settings = GeneralSharedPreferences.getInstance(); String protocol = (String) settings.get(PreferenceKeys.KEY_PROTOCOL); InstanceUploader uploader; Map<String, String> resultMessagesByInstanceId = new HashMap<>(); String deviceId = null; boolean anyFailure = false; if (protocol.equals(getApplicationContext().getString(R.string.protocol_google_sheets))) { if (PermissionUtils.checkIfGetAccountsPermissionGranted(getApplicationContext())) { GoogleAccountsManager accountsManager = new GoogleAccountsManager(Collect.getInstance()); String googleUsername = accountsManager.getSelectedAccount(); if (googleUsername.isEmpty()) { showUploadStatusNotification(true, Collect.getInstance().getString(R.string.google_set_account)); return Result.FAILURE; } accountsManager.getCredential().setSelectedAccountName(googleUsername); uploader = new InstanceGoogleSheetsUploader(accountsManager); try { accountsManager.getDriveHelper().createOrGetIDOfSubmissionsFolder(); } catch (IOException | MultipleFoldersFoundException e) { Timber.d(e, "Exception getting or creating root folder for submissions"); showUploadStatusNotification(true, "Exception getting or creating root folder for submissions"); return Result.FAILURE; } } else { showUploadStatusNotification(true, Collect.getInstance().getString(R.string.odk_permissions_fail)); return Result.FAILURE; } } else { uploader = new InstanceServerUploader(new HttpClientConnection(), new WebCredentialsUtils(), new HashMap<>()); deviceId = new PropertyManager(Collect.getInstance().getApplicationContext()) .getSingularProperty(PropertyManager.withUri(PropertyManager.PROPMGR_DEVICE_ID)); } for (Instance instance : toUpload) { try { String destinationUrl = uploader.getUrlToSubmitTo(instance, deviceId, null); String customMessage = uploader.uploadOneSubmission(instance, destinationUrl); resultMessagesByInstanceId.put(instance.getDatabaseId().toString(), customMessage != null ? customMessage : Collect.getInstance().getString(R.string.success)); // If the submission was successful, delete the instance if either the app-level // delete preference is set or the form definition requests auto-deletion. // TODO: this could take some time so might be better to do in a separate process, // perhaps another worker. It also feels like this could fail and if so should be // communicated to the user. Maybe successful delete should also be communicated? if (InstanceUploader.formShouldBeAutoDeleted(instance.getJrFormId(), (boolean) GeneralSharedPreferences.getInstance() .get(PreferenceKeys.KEY_DELETE_AFTER_SEND))) { Uri deleteForm = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, instance.getDatabaseId().toString()); Collect.getInstance().getContentResolver().delete(deleteForm, null, null); } Collect.getInstance().getDefaultTracker() .send(new HitBuilders.EventBuilder().setCategory("Submission").setAction( protocol.equals(getApplicationContext().getString(R.string.protocol_google_sheets)) ? "HTTP-Sheets auto" : "HTTP auto") .build()); } catch (UploadException e) { Timber.d(e); anyFailure = true; resultMessagesByInstanceId.put(instance.getDatabaseId().toString(), e.getDisplayMessage()); } } String message = formatOverallResultMessage(resultMessagesByInstanceId); showUploadStatusNotification(anyFailure, message); return Result.SUCCESS; }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * Sets the tags of a given prefix for the given item. Any existing tags using the given prefix will be deleted. * @param cr/*from w w w .j av a2 s . c o m*/ * @param item * @param tags * @param prefix */ public static void putTags(ContentResolver cr, Uri item, Collection<String> tags, String prefix) { final ContentValues cv = new ContentValues(); cv.put(Tag.PATH, TaggableItem.toListString(addPrefixToTags(prefix, tags))); cv.put(CV_TAG_PREFIX, prefix); cr.update(Uri.withAppendedPath(item, Tag.PATH), cv, null, null); }