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:com.google.firebase.udacity.greenthumb.PlantDetailActivity.java

private void handleDynamicLink() {
    // Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
    // would automatically launch the deep link if one is found.
    boolean autoLaunchDeepLink = false;
    AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
            .setResultCallback(new ResultCallback<AppInviteInvitationResult>() {
                @Override/*from   w  w w  .j  av  a2s  .  c om*/
                public void onResult(@NonNull AppInviteInvitationResult result) {
                    if (result.getStatus().isSuccess()) {
                        // Extract deep link from Intent
                        Intent intent = result.getInvitationIntent();
                        String deepLink = AppInviteReferral.getDeepLink(intent);

                        // Handle the deep link. For example, open the linked
                        // content, or apply promotional credit to the user's
                        // account.
                        Uri uri = Uri.parse(deepLink);
                        String plantId = uri.getLastPathSegment();
                        mItemId = Integer.parseInt(plantId);
                        getSupportLoaderManager().restartLoader(PLANT_DETAIL_LOADER, null,
                                PlantDetailActivity.this);

                    } else {
                        Log.d(TAG, "getInvitation: no deep link found.");
                    }
                }
            });
}

From source file:com.battlelancer.seriesguide.ui.SearchActivity.java

private void handleIntent(Intent intent) {
    if (intent == null) {
        return;/*www  .jav a  2 s .c  om*/
    }
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Bundle extras = getIntent().getExtras();

        // searching episodes within a show?
        Bundle appData = extras.getBundle(SearchManager.APP_DATA);
        if (appData != null) {
            String showTitle = appData.getString(EpisodeSearchFragment.InitBundle.SHOW_TITLE);
            if (!TextUtils.isEmpty(showTitle)) {
                // change title + switch to episodes tab if show restriction was submitted
                viewPager.setCurrentItem(EPISODES_TAB_INDEX);
            }
        }

        // setting the query automatically triggers a search
        String query = extras.getString(SearchManager.QUERY);
        searchBar.setText(query);
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri data = intent.getData();
        String id = data.getLastPathSegment();
        displayEpisode(id);
        Utils.trackCustomEvent(this, TAG, "Search action", "View");
        finish();
    }
}

From source file:com.ecml.FileUri.java

/** Create a Uri with the given display name
 * //from  w  w  w .  j av  a2s  .  c  o m
 * @param uri
 * @param path
 */
public FileUri(Uri uri, String path) {
    this.uri = uri;
    if (path == null) {
        path = uri.getLastPathSegment();
    }
    displayName = displayNameFromPath(path);
}

From source file:com.renard.documentview.TableOfContentsActivity.java

@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    final Uri documentUri = getIntent().getData();
    final String selection = DocumentContentProvider.Columns.PARENT_ID + "=? OR " + Columns.ID + "=?";
    final String[] args = new String[] { documentUri.getLastPathSegment(), documentUri.getLastPathSegment() };
    return new CursorLoader(this, DocumentContentProvider.CONTENT_URI, PROJECTION, selection, args,
            "created ASC");
}

From source file:com.google.samples.apps.iosched.service.FeedbackListenerService.java

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

    for (DataEvent event : dataEvents) {
        LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                String jsonString = data.getString("response");
                if (TextUtils.isEmpty(jsonString)) {
                    return;
                }//from w  ww. j  a  v  a  2  s. com
                LOGD(TAG, "jsonString is: " + jsonString);
                saveFeedback(jsonString);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}

From source file:com.saarang.samples.apps.iosched.service.FeedbackListenerService.java

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

    for (DataEvent event : dataEvents) {
        LogUtils.LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                String jsonString = data.getString("response");
                if (TextUtils.isEmpty(jsonString)) {
                    return;
                }/*from  w  w  w  .java  2 s  . c om*/
                LogUtils.LOGD(TAG, "jsonString is: " + jsonString);
                saveFeedback(jsonString);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}

From source file:com.sebible.cordova.videosnapshot.VideoSnapshot.java

/**
 * Take snapshots of a video file//ww w  .  java2s.  c o m
 *
 * @param source path of the file
 * @param count of snapshots that are gonna be taken
 */
private void snapshot(final JSONObject options) {
    final CallbackContext context = this.callbackContext;
    this.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            try {
                int count = options.optInt("count", 1);
                int countPerMinute = options.optInt("countPerMinute", 0);
                int quality = options.optInt("quality", 90);
                String source = options.optString("source", "");
                Boolean timestamp = options.optBoolean("timeStamp", true);
                String prefix = options.optString("prefix", "");
                int textSize = options.optInt("textSize", 48);

                if (source.isEmpty()) {
                    throw new Exception("No source provided");
                }

                JSONObject obj = new JSONObject();
                obj.put("result", false);
                JSONArray results = new JSONArray();

                Log.i("snapshot", "Got source: " + source);
                Uri p = Uri.parse(source);
                String filename = p.getLastPathSegment();

                FileInputStream in = new FileInputStream(new File(p.getPath()));
                retriever.setDataSource(in.getFD());
                String tmp = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
                long duration = Long.parseLong(tmp);
                if (countPerMinute > 0) {
                    count = (int) (countPerMinute * duration / (60 * 1000));
                }
                if (count < 1) {
                    count = 1;
                }
                long delta = duration / (count + 1); // Start at duration * 1 and ends at duration * count
                if (delta < 1000) { // min 1s
                    delta = 1000;
                }

                Log.i("snapshot", "duration:" + duration + " delta:" + delta);

                File storage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                for (int i = 1; delta * i < duration && i <= count; i++) {
                    String filename2 = filename.replace('.', '_') + "-snapshot" + i + ".jpg";
                    File dest = new File(storage, filename2);
                    if (!storage.exists() && !storage.mkdirs()) {
                        throw new Exception("Unable to access storage:" + storage.getPath());
                    }
                    FileOutputStream out = new FileOutputStream(dest);
                    Bitmap bm = retriever.getFrameAtTime(i * delta * 1000);
                    if (timestamp) {
                        drawTimestamp(bm, prefix, delta * i, textSize);
                    }
                    bm.compress(Bitmap.CompressFormat.JPEG, quality, out);
                    out.flush();
                    out.close();
                    results.put(dest.getAbsolutePath());
                }

                obj.put("result", true);
                obj.put("snapshots", results);
                context.success(obj);
            } catch (Exception ex) {
                ex.printStackTrace();
                Log.e("snapshot", "Exception:", ex);
                fail("Exception: " + ex.toString());
            } finally {
                try {
                    retriever.release();
                } catch (RuntimeException ex) {
                }
            }
        }
    });
}

From source file:com.android.calendar.event.EditEventActivity.java

private EventInfo getEventInfoFromIntent(Bundle icicle) {
    EventInfo info = new EventInfo();
    long eventId = -1;
    Intent intent = getIntent();/*from   w  w  w .java 2  s .  com*/
    Uri data = intent.getData();
    if (data != null) {
        try {
            eventId = Long.parseLong(data.getLastPathSegment());
        } catch (NumberFormatException e) {
            if (DEBUG) {
                Log.d(TAG, "Create new event");
            }
        }
    } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
        eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
    }

    boolean allDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);

    long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
    long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
    if (end != -1) {
        info.endTime = new Time();
        if (allDay) {
            info.endTime.timezone = Time.TIMEZONE_UTC;
        }
        info.endTime.set(end);
    }
    if (begin != -1) {
        info.startTime = new Time();
        if (allDay) {
            info.startTime.timezone = Time.TIMEZONE_UTC;
        }
        info.startTime.set(begin);
    }
    info.id = eventId;
    info.eventTitle = intent.getStringExtra(Events.TITLE);
    info.calendarId = intent.getLongExtra(Events.CALENDAR_ID, -1);

    if (allDay) {
        info.extraLong = CalendarController.EXTRA_CREATE_ALL_DAY;
    } else {
        info.extraLong = 0;
    }
    return info;
}

From source file:justforcommunity.radiocom.adapters.ProgramListAdapter.java

public String getFileName(String url) {

    Uri uri = Uri.parse(url);
    String filename = uri.getLastPathSegment();

    return filename.trim();
}

From source file:com.doplgangr.secrecy.FileSystem.Vault.java

public String addFile(final Context context, final Uri uri) {
    String filename = uri.getLastPathSegment();
    try {/*ww w.  j  av a 2  s. c om*/
        String realPath = getPath(context, uri);
        Util.log(realPath, filename);
        filename = new java.io.File(realPath).getName();
        // If we can use real path, better use one.
    } catch (Exception ignored) {
        // Leave it.
    }
    if (!filename.contains("_thumb") && !filename.contains(".nomedia")) {
        ContentResolver cR = context.getContentResolver();
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        String type = mime.getExtensionFromMimeType(cR.getType(uri));
        if (type != null)
            filename = Base64Coder.encodeString(FilenameUtils.removeExtension(filename)) + "." + type;
    }
    InputStream is = null;
    OutputStream out = null;
    try {
        InputStream stream = context.getContentResolver().openInputStream(uri);
        java.io.File addedFile = new java.io.File(path + "/" + filename);
        addedFile.delete();
        addedFile.createNewFile();
        is = new BufferedInputStream(stream);
        byte buffer[] = new byte[Config.bufferSize];
        int count;
        AES_Encryptor enc = new AES_Encryptor(key);
        out = new CipherOutputStream(new FileOutputStream(addedFile), enc.encryptstream());
        while ((count = is.read(buffer)) != -1)
            out.write(buffer, 0, count);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (is != null) {
                is.close();
            }
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return filename;
}