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:ca.rmen.android.poetassistant.main.MainActivity.java

private void handleDeepLink(Uri uri) {
    Log.d(TAG, "handleDeepLink() called with: " + "uri = [" + uri + "]");
    if (uri == null)
        return;//from   w  w  w .  ja va2s.  c  o  m
    String word = uri.getLastPathSegment();
    if (Constants.DEEP_LINK_QUERY.equals(uri.getHost())) {
        mSearch.search(word);
        mBinding.viewPager.setCurrentItem(mPagerAdapter.getPositionForTab(Tab.DICTIONARY));
    } else {
        Tab tab = Tab.parse(uri.getHost());
        if (tab != null)
            mSearch.search(word, tab);
    }
}

From source file:nl.sogeti.android.gpstracker.streaming.CustomUpload.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(this, "onReceive(Context, Intent)");
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String prefUrl = preferences.getString(Constants.CUSTOMUPLOAD_URL, "http://www.example.com");
    Integer prefBacklog = Integer
            .valueOf(preferences.getString(Constants.CUSTOMUPLOAD_BACKLOG, CUSTOM_UPLOAD_BACKLOG_DEFAULT));
    Location loc = intent.getParcelableExtra(ExternalConstants.EXTRA_LOCATION);
    Uri trackUri = intent.getParcelableExtra(ExternalConstants.EXTRA_TRACK);
    String buildUrl = prefUrl;//from  w  w w. j a v  a 2s  . c om
    buildUrl = buildUrl.replace("@LAT@", Double.toString(loc.getLatitude()));
    buildUrl = buildUrl.replace("@LON@", Double.toString(loc.getLongitude()));
    buildUrl = buildUrl.replace("@ID@", trackUri.getLastPathSegment());
    buildUrl = buildUrl.replace("@TIME@", Long.toString(loc.getTime()));
    buildUrl = buildUrl.replace("@SPEED@", Float.toString(loc.getSpeed()));
    buildUrl = buildUrl.replace("@ACC@", Float.toString(loc.getAccuracy()));
    buildUrl = buildUrl.replace("@ALT@", Double.toString(loc.getAltitude()));
    buildUrl = buildUrl.replace("@BEAR@", Float.toString(loc.getBearing()));

    URL uploadUri;
    try {
        uploadUri = new URL(buildUrl);
        if (uploadUri.getHost() != null
                && ("http".equals(uploadUri.getProtocol()) || "https".equals(uploadUri.getProtocol()))) {
            sRequestBacklog.add(uploadUri);
        } else {
            Log.e(this, "URL does not have correct scheme or host " + uploadUri);
        }
        if (sRequestBacklog.size() > prefBacklog) {
            sRequestBacklog.poll();
        }
        new Uploader(context).execute();
    } catch (IOException e) {
        notifyError(context, e);
    }
}

From source file:net.sf.asap.Player.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Uri uri = getIntent().getData();
    filename = uri.getLastPathSegment();
    ZipFile zip = null;/* w w w  . jav a 2  s .co m*/
    final byte[] module = new byte[ASAPInfo.MAX_MODULE_LENGTH];
    int moduleLen;
    try {
        InputStream is;
        if (Util.isZip(filename)) {
            zip = new ZipFile(uri.getPath());
            filename = uri.getFragment();
            is = zip.getInputStream(zip.getEntry(filename));
        } else {
            try {
                is = getContentResolver().openInputStream(uri);
            } catch (FileNotFoundException ex) {
                if (uri.getScheme().equals("http"))
                    is = httpGet(uri);
                else
                    throw ex;
            }
        }
        moduleLen = readAndClose(is, module);
    } catch (IOException ex) {
        showError(R.string.error_reading_file);
        return;
    } finally {
        Util.close(zip);
    }
    try {
        asap.load(filename, module, moduleLen);
    } catch (Exception ex) {
        showError(R.string.invalid_file);
        return;
    }
    info = asap.getInfo();

    setTitle(R.string.playing_title);
    setContentView(R.layout.playing);
    setTag(R.id.name, info.getTitleOrFilename());
    setTag(R.id.author, info.getAuthor());
    setTag(R.id.date, info.getDate());
    findViewById(R.id.stop_button).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });
    mediaController = new MediaController(this, false);
    mediaController.setAnchorView(getContentView());
    mediaController.setMediaPlayer(new MediaController.MediaPlayerControl() {
        public boolean canPause() {
            return !isPaused();
        }

        public boolean canSeekBackward() {
            return false;
        }

        public boolean canSeekForward() {
            return false;
        }

        public int getBufferPercentage() {
            return 100;
        }

        public int getCurrentPosition() {
            return asap.getPosition();
        }

        public int getDuration() {
            return info.getDuration(song);
        }

        public boolean isPlaying() {
            return !isPaused();
        }

        public void pause() {
            audioTrack.pause();
        }

        public void seekTo(int pos) {
            seek(pos);
        }

        public void start() {
            resume();
        }
    });
    if (info.getSongs() > 1) {
        mediaController.setPrevNextListeners(new OnClickListener() {
            public void onClick(View v) {
                playNextSong();
            }
        }, new OnClickListener() {
            public void onClick(View v) {
                playPreviousSong();
            }
        });
    }
    new Handler().postDelayed(new Runnable() {
        public void run() {
            mediaController.show();
        }
    }, 500);

    stop = false;
    playSong(info.getDefaultSong());
    new Thread(this).start();
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private static Uri insert(Context context, String[] to, MMSPart[] parts, String subject) {
    try {/*from  w  w w  .jav  a2 s  .  com*/
        Uri destUri = Uri.parse("content://mms");

        Set<String> recipients = new HashSet<>();
        recipients.addAll(Arrays.asList(to));
        long thread_id = Utils.getOrCreateThreadId(context, recipients);

        // Create a dummy sms
        ContentValues dummyValues = new ContentValues();
        dummyValues.put("thread_id", thread_id);
        dummyValues.put("body", " ");
        Uri dummySms = context.getContentResolver().insert(Uri.parse("content://sms/sent"), dummyValues);

        // Create a new message entry
        long now = System.currentTimeMillis();
        ContentValues mmsValues = new ContentValues();
        mmsValues.put("thread_id", thread_id);
        mmsValues.put("date", now / 1000L);
        mmsValues.put("msg_box", 4);
        //mmsValues.put("m_id", System.currentTimeMillis());
        mmsValues.put("read", true);
        mmsValues.put("sub", subject != null ? subject : "");
        mmsValues.put("sub_cs", 106);
        mmsValues.put("ct_t", "application/vnd.wap.multipart.related");

        long imageBytes = 0;

        for (MMSPart part : parts) {
            imageBytes += part.Data.length;
        }

        mmsValues.put("exp", imageBytes);

        mmsValues.put("m_cls", "personal");
        mmsValues.put("m_type", 128); // 132 (RETRIEVE CONF) 130 (NOTIF IND) 128 (SEND REQ)
        mmsValues.put("v", 19);
        mmsValues.put("pri", 129);
        mmsValues.put("tr_id", "T" + Long.toHexString(now));
        mmsValues.put("resp_st", 128);

        // Insert message
        Uri res = context.getContentResolver().insert(destUri, mmsValues);
        String messageId = res.getLastPathSegment().trim();

        // Create part
        for (MMSPart part : parts) {
            if (part.MimeType.startsWith("image")) {
                createPartImage(context, messageId, part.Data, part.MimeType);
            } else if (part.MimeType.startsWith("text")) {
                createPartText(context, messageId, new String(part.Data, "UTF-8"));
            }
        }

        // Create addresses
        for (String addr : to) {
            createAddr(context, messageId, addr);
        }

        //res = Uri.parse(destUri + "/" + messageId);

        // Delete dummy sms
        context.getContentResolver().delete(dummySms, null, null);

        return res;
    } catch (Exception e) {
        if (LOCAL_LOGV)
            Log.v(TAG, "still an error saving... :(");
        Log.e(TAG, "exception thrown", e);
    }

    return null;
}

From source file:com.bt.download.android.gui.UniversalScanner.java

/**
 * Android geniuses put a .nomedia file on the .../Android/data/ folder
 * inside the secondary external storage path, therefore, all attempts
 * to use MediaScannerConnection to scan a media file fail. Therefore we
 * have this method to insert the file's metadata manually on the content provider.
 * @param path//from w  ww .  j  a  v  a2  s  . c  o m
 */
private void scanPrivateFile(Uri oldUri, String filePath, MediaType mt) {
    try {
        int n = context.getContentResolver().delete(oldUri, null, null);
        if (n > 0) {
            LOG.debug("Deleted from Files provider: " + oldUri);
        }
        Uri uri = nativeScanFile(context, filePath);

        if (uri != null) {
            FileDescriptor fd = new FileDescriptor();
            fd.fileType = (byte) mt.getId();
            fd.id = Integer.valueOf(uri.getLastPathSegment());

            shareFinishedDownload(fd);
        }
    } catch (Throwable e) {
        // eat
        e.printStackTrace();
    }
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

/** Called when the activity is first created. */
@Override/*from  w w w  .  j a  v  a 2 s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final ImageView imagePreview = (ImageView) findViewById(R.id.ImagePreview);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    Uri mImageUri = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                int origId = Integer.parseInt(mImageUri.getLastPathSegment());
                Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), origId,
                        MediaStore.Images.Thumbnails.MINI_KIND, (BitmapFactory.Options) null);
                imagePreview.setImageBitmap(bitmap);
            }
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            tag_suggests);
    final MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.TagEditView);
    textView.setAdapter(adapter);
    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    final Button button = (Button) findViewById(R.id.ZeitgeistSubmit);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            submitImage(textView.getText().toString());
        }
    });
}

From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java

public void deleteTrack(Uri uri) {

    Track track = TracksManager.findTrack(getContentResolver(), uri);

    if (track != null) {
        String id = uri.getLastPathSegment();
        int rowsDeleted = getContentResolver().delete(uri, null, null);

        if (rowsDeleted > 0) {

            try {
                final HttpDelete delete = new HttpDelete(
                        "http://api.soundcloud.com/me/tracks/" + track.getmIdTrack());
                Soundroid.getSc().signRequest(delete);
                HttpResponse response = HttpManager.newInstance().execute(delete);

                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    showNotification("Track " + track.getmTitle() + " deleted");
                    Log.i(TAG, "Deleted " + rowsDeleted + " track with local id " + id + " and remote id "
                            + track.getmIdTrack());

                } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                    showNotification("Track " + track.getmTitle() + " not found");
                }/*from w ww . j a v  a  2 s.c  o  m*/

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } else {
            showNotification("Track " + uri + " not found");
        }
    }
}

From source file:th.in.ffc.person.visit.VisitDefaultActivity.java

protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setRetriveVisitData(false);//from www .j ava 2s.  co  m
    super.onCreate(savedInstanceState);
    setContentView(R.layout.visit_default_activity);

    setSupportProgressBarIndeterminateVisibility(false);
    doSetupMeasurement(null);
    doSetupDiagnose(null);

    mTimeStart = DateTime.getCurrentTime();

    String action = getIntent().getAction();
    Uri data = getIntent().getData();

    if (action.equals(Action.INSERT)) {
        mPid = data.getLastPathSegment();
        if (savedInstanceState != null) {
            mVisitNo = savedInstanceState.getString(Visit.NO);
        }

        if (TextUtils.isEmpty(mVisitNo)) {
            getSupportLoaderManager().initLoader(LOAD_MAXVISIT, null, this);
            getSupportLoaderManager().initLoader(LOAD_LAST_MEASURE, null, this);
        } else {
            getSupportActionBar().setSubtitle("Visit #" + mVisitNo);
        }

    } else if (action.equals(Action.EDIT)) {
        mVisitNo = data.getLastPathSegment();
        mPid = getIntent().getStringExtra(Person.PID);
        if (TextUtils.isEmpty(mPid))
            throw new IllegalArgumentException("need person.pid to edit visit");
        getSupportActionBar().setSubtitle("Visit #" + mVisitNo);
        getSupportLoaderManager().initLoader(LOAD_SAVED_VISIT, null, this);
    }
}

From source file:ca.rmen.android.scrumchatter.team.Teams.java

public void createTeam(final String teamName) {
    Log.v(TAG, "createTeam, name=" + teamName);
    // Ignore an empty name.
    if (!TextUtils.isEmpty(teamName)) {
        // Create the new team in a background thread.
        Schedulers.io().scheduleDirect(() -> {
            ContentValues values = new ContentValues(1);
            values.put(TeamColumns.TEAM_NAME, teamName);
            Uri newTeamUri = mActivity.getContentResolver().insert(TeamColumns.CONTENT_URI, values);
            if (newTeamUri != null) {
                int newTeamId = Integer.valueOf(newTeamUri.getLastPathSegment());
                Prefs.getInstance(mActivity).setTeamId(newTeamId);
            }/* w ww . jav a  2 s.  c o  m*/
        });
    }
}

From source file:org.musicmod.android.app.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();/*from w  w  w . ja va 2s. c  om*/

    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) };
            MusicUtils.playAll(getActivity(), 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);
}