List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:com.android.music.AlbumBrowserFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub switch (requestCode) { case SCAN_DONE: if (resultCode == getActivity().RESULT_CANCELED) { getActivity().finish();//from ww w. j a va 2s . c o m } else { getAlbumCursor(mAdapter.getQueryHandler(), null); } break; case NEW_PLAYLIST: if (resultCode == getActivity().RESULT_OK) { Uri uri = data.getData(); if (uri != null) { long[] list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId)); MusicUtils.addToPlaylist(getActivity(), list, Long.parseLong(uri.getLastPathSegment())); } } break; } }
From source file:com.example.google.play.apkx.SampleDownloaderActivity.java
/** * This starts the movie by starting the video player activity with a * content URI for our custom APK extension content provider. *//*from w w w . j a va 2 s.co m*/ private void startMovie() { // launch the movie player activity Uri mediaUri = Uri.withAppendedPath(SampleZipFileProvider.ASSET_URI, "big_buck_bunny_720p_surround.m4v"); Intent intent = new Intent(); intent.setData(mediaUri); intent.putExtra(Intent.EXTRA_TITLE, mediaUri.getLastPathSegment()); intent.setClass(this, SampleVideoPlayerActivity.class); startActivity(intent); finish(); }
From source file:edu.mit.mobile.android.locast.data.MediaSync.java
/** * @param pubUri/*from w w w.j av a 2s. c o m*/ * public media uri * @return The local path on disk for the given remote video. * @throws SyncException */ public File getFilePath(Uri pubUri) throws SyncException { // pull off the server's name for this file. final String localFile = pubUri.getLastPathSegment(); final File saveFile = new File(getSaveLocation(), localFile); return saveFile; }
From source file:com.kyakujin.android.autoeco.ui.MainActivity.java
private void setTime() { // CustomTimePickerDialog????? TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { /** DO NOTHING */ }/*w w w. ja v a2 s . co m*/ }; // ????????????? if (mCurrentSchedUri != null) { SchedDAO dao = new SchedDAO(mActivity); SchedModel model = new SchedModel(); model = dao.readToSchedModelById(Integer.valueOf(mCurrentSchedUri.getLastPathSegment())); if (model != null) { mTimeData.setHour(model.getHour()); mTimeData.setMinute(model.getMinute()); Logger.d(TAG, "get timedata hour=" + model.getHour() + ", minute=" + model.getMinute()); } } timePickerDialog = new CustomTimePickerDialog(this, listener, mTimeData.getHour(), mTimeData.getMinute(), true); timePickerDialog.setTimeData(mTimeData); timePickerDialog.setTitle(getResources().getString(R.string.alert_title_settime)); // ? timePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } // end of onclick } // end of listener ); timePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ???? if (mTimeData == null) return; int hour = mTimeData.getHour(); int minute = mTimeData.getMinute(); Logger.v("Time", String.format("%02d:%02d", hour, minute)); SchedModel model = new SchedModel(); model.setHour(hour); model.setMinute(minute); model.setHour_minute_string(String.format("%02d:%02d", hour, minute)); SchedDAO dao = new SchedDAO(mActivity); // ????? if (mCurrentSchedUri != null) { model.setId(Integer.valueOf(mCurrentSchedUri.getLastPathSegment())); dao.updateTime(model); activityRestart(); // ??? } else { // ????? if (dao.countSchedFromTime(hour, minute) > 0) return; model.setEnabled(true); model.setPattern(Conf.DEFAULT_REPEAT_PATTERN); Uri uri = dao.insertSched(model); if (uri == null) return; model.setId(Integer.valueOf(uri.getLastPathSegment())); // mSchedListAdapter.notifyDataSetChanged(); transitionToSchedSetting(Integer.valueOf(uri.getLastPathSegment())); } SchedAlarmManager am = new SchedAlarmManager(mActivity); am.addAlarm(model); // ? mCurrentSchedUri = null; mTimeData.setHour(0); mTimeData.setMinute(0); } // end of onclick } // end of listener ); timePickerDialog.show(); }
From source file:mobisocial.bento.anyshare.ui.FeedItemListActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent ret) { if (requestCode == REQUEST_PICK) { if (resultCode == RESULT_OK) { Log.d(TAG, ret.toString());/* www . j a v a2s . co m*/ Uri uri = ret.getData(); Intent intent = new Intent(this, PostActivity.class); intent.setAction(Intent.ACTION_SEND); String mimetype = getContentResolver().getType(uri); String ext = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); MimeTypeMap mime = MimeTypeMap.getSingleton(); if (mimetype == null || mimetype.isEmpty()) { if (!ext.isEmpty()) { mimetype = mime.getMimeTypeFromExtension(ext); } } String fname = uri.getLastPathSegment(); if (ext.isEmpty()) { fname += "." + mime.getExtensionFromMimeType(mimetype); } intent.setType(mimetype); intent.putExtra(Intent.EXTRA_SUBJECT, fname); intent.putExtra(Intent.EXTRA_TEXT, ""); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivityForResult(intent, HomeActivity.REQUEST_VIEW); } } super.onActivityResult(requestCode, resultCode, ret); }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java
/** * Starts downloading the S3 object specified by the bucket and the key to * the given file. The file must be a valid file. Directory isn't supported. * Note that if the given file exists, it'll be overwritten. * * @param bucket The name of the bucket containing the object to download. * @param key The key under which the object to download is stored. * @param file The file to download the object's data to. * @param listener a listener to attach to transfer observer. * @return A TransferObserver used to track download progress and state *//*from www . j av a2 s .c o m*/ public TransferObserver download(String bucket, String key, File file, TransferListener listener) { if (file == null || file.isDirectory()) { throw new IllegalArgumentException("Invalid file: " + file); } final Uri uri = dbUtil.insertSingleTransferRecord(TransferType.DOWNLOAD, bucket, key, file); final int recordId = Integer.parseInt(uri.getLastPathSegment()); if (file.isFile()) { LOGGER.warn("Overwrite existing file: " + file); file.delete(); } sendIntent(TransferService.INTENT_ACTION_TRANSFER_ADD, recordId); return new TransferObserver(recordId, dbUtil, bucket, key, file, listener); }
From source file:com.android.music.AlbumBrowserActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case SCAN_DONE: if (resultCode == RESULT_CANCELED) { finish();/*from ww w . j a va 2 s . com*/ } else { getAlbumCursor(mAdapter.getQueryHandler(), null); } break; case NEW_PLAYLIST: if (resultCode == RESULT_OK) { Uri uri = intent.getData(); if (uri != null) { long[] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId)); MusicUtils.addToPlaylist(this, list, Long.parseLong(uri.getLastPathSegment())); } } break; } }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Check that inserting and removing a note into default deck works as expected *//*from w ww .j a v a 2s .c o m*/ public void testInsertAndRemoveNote() throws Exception { // Get required objects for test final ContentResolver cr = getContext().getContentResolver(); final Collection col = CollectionHelper.getInstance().getCol(getContext()); final AddContentApi api = new AddContentApi(getContext()); // Add the note Uri newNoteUri = api.addNewNote(mModelId, 1, TEST_NOTE_FIELDS, TEST_TAG); assertNotNull("Check that URI returned from addNewNote is not null", newNoteUri); // Check that it looks as expected Note addedNote = new Note(col, Long.parseLong(newNoteUri.getLastPathSegment())); addedNote.load(); assertTrue("Check that fields were set correctly", Arrays.equals(addedNote.getFields(), TEST_NOTE_FIELDS)); assertEquals("Check that tag was set correctly", TEST_TAG, addedNote.getTags().get(0)); int expectedNumCards = col.getModels().get(mModelId).getJSONArray("tmpls").length(); assertEquals("Check that correct number of cards generated", expectedNumCards, addedNote.cards().size()); // Now delete the note cr.delete(newNoteUri, null, null); try { addedNote.load(); fail("Expected RuntimeException to be thrown when deleting note"); } catch (RuntimeException e) { // Expect RuntimeException to be thrown when loading deleted note } }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java
/** * Starts uploading the file to the given bucket, using the given key. The * file must be a valid file. Directory isn't supported. * * @param bucket The name of the bucket to upload the new object to. * @param key The key in the specified bucket by which to store the new * object.//from ww w . j a va 2 s . c o m * @param file The file to upload. * @param metadata The S3 metadata to associate with this object * @param cannedAcl The canned ACL to associate with this object * @param listener a listener to attach to transfer observer. * @return A TransferObserver used to track upload progress and state */ public TransferObserver upload(String bucket, String key, File file, ObjectMetadata metadata, CannedAccessControlList cannedAcl, TransferListener listener) { if (file == null || file.isDirectory() || !file.exists()) { throw new IllegalArgumentException("Invalid file: " + file); } int recordId = 0; if (shouldUploadInMultipart(file)) { recordId = createMultipartUploadRecords(bucket, key, file, metadata, cannedAcl); } else { final Uri uri = dbUtil.insertSingleTransferRecord(TransferType.UPLOAD, bucket, key, file, metadata, cannedAcl); recordId = Integer.parseInt(uri.getLastPathSegment()); } sendIntent(TransferService.INTENT_ACTION_TRANSFER_ADD, recordId); return new TransferObserver(recordId, dbUtil, bucket, key, file, listener); }
From source file:org.getlantern.firetweet.service.BackgroundOperationService.java
private void handleUpdateStatusIntent(final Intent intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); final ParcelableStatusUpdate status = intent.getParcelableExtra(EXTRA_STATUS); final Parcelable[] status_parcelables = intent.getParcelableArrayExtra(EXTRA_STATUSES); final ParcelableStatusUpdate[] statuses; if (status_parcelables != null) { statuses = new ParcelableStatusUpdate[status_parcelables.length]; for (int i = 0, j = status_parcelables.length; i < j; i++) { statuses[i] = (ParcelableStatusUpdate) status_parcelables[i]; }/*from ww w.j a va2 s .c om*/ } else if (status != null) { statuses = new ParcelableStatusUpdate[1]; statuses[0] = status; } else return; startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotificaion(this, builder, 0, null)); for (final ParcelableStatusUpdate item : statuses) { mNotificationManager.notify(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotificaion(this, builder, 0, item)); final ContentValues draftValues = ContentValuesCreator.createStatusDraft(item, ParcelableAccount.getAccountIds(item.accounts)); final Uri draftUri = mResolver.insert(Drafts.CONTENT_URI, draftValues); final long draftId = ParseUtils.parseLong(draftUri.getLastPathSegment(), -1); mTwitter.addSendingDraftId(draftId); final List<SingleResponse<ParcelableStatus>> result = updateStatus(builder, item); boolean failed = false; Exception exception = null; final Expression where = Expression.equals(Drafts._ID, draftId); final List<Long> failedAccountIds = ListUtils.fromArray(ParcelableAccount.getAccountIds(item.accounts)); for (final SingleResponse<ParcelableStatus> response : result) { if (response.getData() == null) { failed = true; if (exception == null) { exception = response.getException(); } } else if (response.getData().account_id > 0) { failedAccountIds.remove(response.getData().account_id); } } if (result.isEmpty()) { showErrorMessage(R.string.action_updating_status, getString(R.string.no_account_selected), false); } else if (failed) { // If the status is a duplicate, there's no need to save it to // drafts. if (exception instanceof TwitterException && ((TwitterException) exception) .getErrorCode() == StatusCodeMessageUtils.STATUS_IS_DUPLICATE) { showErrorMessage(getString(R.string.status_is_duplicate), false); } else { final ContentValues accountIdsValues = new ContentValues(); accountIdsValues.put(Drafts.ACCOUNT_IDS, ListUtils.toString(failedAccountIds, ',', false)); mResolver.update(Drafts.CONTENT_URI, accountIdsValues, where.getSQL(), null); showErrorMessage(R.string.action_updating_status, exception, true); displayTweetNotSendNotification(); } } else { showOkMessage(R.string.status_updated, false); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); if (item.media != null) { for (final ParcelableMediaUpdate media : item.media) { final String path = getImagePathFromUri(this, Uri.parse(media.uri)); if (path != null) { if (!new File(path).delete()) { Log.d(LOGTAG, String.format("unable to delete %s", path)); } } } } } mTwitter.removeSendingDraftId(draftId); if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET, false)) { mHandler.post(new Runnable() { @Override public void run() { mTwitter.refreshAll(); } }); } } stopForeground(false); mNotificationManager.cancel(NOTIFICATION_ID_UPDATE_STATUS); }