Example usage for android.net Uri getLastPathSegment

List of usage examples for android.net Uri getLastPathSegment

Introduction

In this page you can find the example usage for android.net Uri getLastPathSegment.

Prototype

@Nullable
public abstract String getLastPathSegment();

Source Link

Document

Gets the decoded last segment in the path.

Usage

From source file:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();//  w  ww . j  a  v  a 2 s . c o  m

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            mUtils.playAll(list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:br.com.devfest.norte.wear.HomeListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        Uri uri = event.getDataItem().getUri();
        LOGD(TAG, "onDataChanged(): Received a data item change with uri: " + uri.toString());
        if (event.getType() == DataEvent.TYPE_DELETED) {
            if (uri.getPath().startsWith(PATH_FEEDBACK)) {
                dismissLocalNotification(uri.getLastPathSegment());
            }/*from   w ww. j a  va2s .  c  o m*/
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (uri.getPath().startsWith(PATH_FEEDBACK)) {
                setupNotification(event.getDataItem());
            }
        }
    }
}

From source file:com.securecomcode.text.contacts.ContactAccessor.java

public ContactData getContactData(Context context, Uri uri) {
    return getContactData(context, getNameFromContact(context, uri), Long.parseLong(uri.getLastPathSegment()));
}

From source file:com.ncode.android.apps.schedo.iowear.HomeListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Utils.LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        Uri uri = event.getDataItem().getUri();
        Utils.LOGD(TAG, "onDataChanged(): Received a data item change with uri: " + uri.toString());
        if (event.getType() == DataEvent.TYPE_DELETED) {
            if (uri.getPath().startsWith(PATH_FEEDBACK)) {
                dismissLocalNotification(uri.getLastPathSegment());
            }/*w  w  w . j ava 2  s. c  om*/
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (uri.getPath().startsWith(PATH_FEEDBACK)) {
                setupNotification(event.getDataItem());
            }
        }
    }
}

From source file:com.android.messaging.mmslib.util.PduCache.java

@Override
public synchronized PduCacheEntry purge(Uri uri) {
    int match = URI_MATCHER.match(uri);
    switch (match) {
    case MMS_ALL_ID:
        return purgeSingleEntry(uri);
    case MMS_INBOX_ID:
    case MMS_SENT_ID:
    case MMS_DRAFTS_ID:
    case MMS_OUTBOX_ID:
        String msgId = uri.getLastPathSegment();
        return purgeSingleEntry(Uri.withAppendedPath(Mms.CONTENT_URI, msgId));
    // Implicit batch of purge, return null.
    case MMS_ALL:
    case MMS_CONVERSATION:
        purgeAll();/*from  ww  w .j  ava 2  s  .c o m*/
        return null;
    case MMS_INBOX:
    case MMS_SENT:
    case MMS_DRAFTS:
    case MMS_OUTBOX:
        purgeByMessageBox(MATCH_TO_MSGBOX_ID_MAP.get(match));
        return null;
    case MMS_CONVERSATION_ID:
        purgeByThreadId(ContentUris.parseId(uri));
        return null;
    default:
        return null;
    }
}

From source file:com.galois.qrstream.MainActivity.java

private String getNameFromURI(Uri uri) {
    String name;//from w w w  .java  2 s. com
    Cursor metadata = getContentResolver().query(uri, new String[] { OpenableColumns.DISPLAY_NAME }, null, null,
            null);
    if (metadata != null && metadata.moveToFirst()) {
        name = metadata.getString(0);
    } else {
        name = uri.getLastPathSegment();
    }
    return name;
}

From source file:com.dwdesign.tweetings.activity.ImageViewerActivity.java

private void saveImage() {
    if (mImageFile != null && mImageFile.exists()) {
        final Uri uri = getIntent().getData();
        if (uri == null)
            return;
        final String file_name = uri.getLastPathSegment();
        final BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;//w ww. j av  a  2s.  co m
        BitmapFactory.decodeFile(mImageFile.getPath(), o);
        final String mime_type = o.outMimeType;
        String file_name_with_suffix = null;
        if (file_name.matches("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|PNG|JPG|JPEG|GIF|BMP)$")) {
            file_name_with_suffix = file_name;
        } else {
            if (mime_type == null)
                return;
            if (mime_type.startsWith("image/") && !"image/*".equals(mime_type)) {
                file_name_with_suffix = file_name + "." + mime_type.substring(5);
            }
        }
        final Intent intent = new Intent(INTENT_ACTION_SAVE_FILE);
        intent.setPackage(getPackageName());
        intent.putExtra(INTENT_KEY_FILE_SOURCE, mImageFile.getPath());
        intent.putExtra(INTENT_KEY_FILENAME, file_name_with_suffix);
        startActivity(intent);
    }
}

From source file:com.apptentive.android.sdk.model.FileMessage.java

/**
 * This method stores an image, and compresses it in the process so it doesn't fill up the disk. Therefore, do not use
 * it to store an exact copy of the file in question.
 */// w w  w  .ja v a  2  s. com
public boolean internalCreateStoredImage(Context context, String uriString) {
    Uri uri = Uri.parse(uriString);

    ContentResolver resolver = context.getContentResolver();
    String mimeType = resolver.getType(uri);
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String extension = mime.getExtensionFromMimeType(mimeType);
    setFileName(uri.getLastPathSegment() + "." + extension);
    setMimeType(mimeType);

    // Create a file to save locally.
    String localFileName = getStoredFileId();
    File localFile = new File(localFileName);

    // Copy the file contents over.
    InputStream is = null;
    CountingOutputStream cos = null;
    try {
        is = new BufferedInputStream(context.getContentResolver().openInputStream(uri));
        cos = new CountingOutputStream(
                new BufferedOutputStream(context.openFileOutput(localFile.getPath(), Context.MODE_PRIVATE)));
        System.gc();
        Bitmap smaller = ImageUtil.createScaledBitmapFromStream(is, MAX_STORED_IMAGE_EDGE,
                MAX_STORED_IMAGE_EDGE, null);
        // TODO: Is JPEG what we want here?
        smaller.compress(Bitmap.CompressFormat.JPEG, 95, cos);
        cos.flush();
        Log.d("Bitmap saved, size = " + (cos.getBytesWritten() / 1024) + "k");
        smaller.recycle();
        System.gc();
    } catch (FileNotFoundException e) {
        Log.e("File not found while storing image.", e);
        return false;
    } catch (Exception e) {
        Log.a("Error storing image.", e);
        return false;
    } finally {
        Util.ensureClosed(is);
        Util.ensureClosed(cos);
    }

    // Create a StoredFile database entry for this locally saved file.
    StoredFile storedFile = new StoredFile();
    storedFile.setId(getStoredFileId());
    storedFile.setOriginalUri(uri.toString());
    storedFile.setLocalFilePath(localFile.getPath());
    storedFile.setMimeType("image/jpeg");
    FileStore db = ApptentiveDatabase.getInstance(context);
    return db.putStoredFile(storedFile);
}

From source file:com.ola.insta.BookingAcivity.java

/**
 * Receiving speech input//from   w  ww .ja v a  2s .co  m
 * */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && null != data) {
        switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT:

            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            boolean isMatched = false;
            for (String string : result) {
                if (string.contains(Constants.VOICE_MESSAGE)) {
                    /*
                     * Toast.makeText( getApplicationContext(),
                     * getApplicationContext().getString(
                     * R.string.cab_booked), Toast.LENGTH_SHORT).show();
                     */

                    // Call REST API

                    if (Utilities.isNetworkAvailable(this)) {
                        new GetCabBookingRequestTask().execute();
                    } else {
                        Utilities mUltilities = new Utilities();
                        mUltilities.showDialogConfirm(BookingAcivity.this, "Message",
                                "Please check network connection", true).show();
                    }
                    isMatched = true;
                    break;
                }

            }
            if (!isMatched) {
                speakOut("Please try again!");
                Toast.makeText(getApplicationContext(),
                        getApplicationContext().getString(R.string.speech_try_again), Toast.LENGTH_SHORT)
                        .show();
            }

            break;

        case REQ_CODE_SELECT_CONTACT:
            Uri uri = data.getData();
            String id = uri.getLastPathSegment();

            Cursor contact = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?",
                    new String[] { id }, null);
            if (contact.moveToFirst()) {
                if (contact.getString(contact.getColumnIndex(Phone.HAS_PHONE_NUMBER)) != null) {

                    final String contactName = contact.getString(contact.getColumnIndex(Phone.DISPLAY_NAME));
                    final String phoneNum = contact.getString(contact.getColumnIndex(Phone.NUMBER));

                    MaterialDialog dialog = new MaterialDialog(context,
                            context.getString(R.string.emergency_contact),
                            "Name : " + contactName + "\nNumber : " + phoneNum, context.getString(R.string.add),
                            context.getString(R.string.cancel));
                    dialog.setOnAcceptButtonClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            saveToShrPref(contactName, phoneNum);
                            Toast.makeText(context, "Emergency contact saved successfully!", Toast.LENGTH_LONG)
                                    .show();

                        }
                    });
                    dialog.setOnCancelButtonClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    });
                    dialog.show();

                } else
                    Toast.makeText(context, context.getString(R.string.contact_dont_have_number),
                            Toast.LENGTH_LONG).show();
            }
            break;

        default:
            break;
        }

    }
}

From source file:com.nextgis.maplibui.service.TrackerService.java

private void restoreData() {
    Uri mNewTrack = Uri.parse(mSharedPreferencesTemp.getString(TRACK_URI, ""));
    mTrackId = mNewTrack.getLastPathSegment();
    mIsRunning = true;/*from  w w w .java2 s . c o m*/
    addSplitter();
}