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.gmail.emerssso.srbase.database.SRContentProvider.java

/**
 * Deletes an item indecated by an ID Uri
 * @param uri Uri of item to delete//from  w  w w.j a v a2s.  c o  m
 * @param selection selection for items to delete
 * @param selArgs arguments for selection
 * @param wDB DB to act on
 * @param tableName Table to delete from
 * @return number of rows deleted
 */
private static int deleteIdTypeUri(Uri uri, String selection, String[] selArgs, SQLiteDatabase wDB,
        String tableName) {
    String id = uri.getLastPathSegment();
    if (StringUtils.isBlank(selection)) {
        selection = "_id =" + id;
    } else {
        selection = "_id =" + id + " and " + selection;
    }
    return wDB.delete(tableName, selection, selArgs);
}

From source file:at.ac.uniklu.mobile.sportal.util.Utils.java

public static String getContentDispositionOrUrlFilename(String contentDisposition, Uri uri) {
    String filename = getContentDispositionFilename(contentDisposition);
    if (filename == null) {
        filename = uri.getLastPathSegment();
    }// w w  w .j a va2  s.c  o  m
    return filename;
}

From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java

public static String getName(Context context, Uri uri) {

    if (uri == null || uri.equals(Uri.EMPTY))
        return "";

    String fileName = "";
    try {//from  www  . ja va  2 s  .c om
        String scheme = uri.getScheme();
        if (scheme.equals("file")) {
            fileName = uri.getLastPathSegment();
        } else if (scheme.equals("content")) {
            String[] proj = { MediaStore.Images.Media.DISPLAY_NAME };
            Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
            if (cursor != null && cursor.getCount() != 0) {
                int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
                cursor.moveToFirst();
                fileName = cursor.getString(columnIndex);
            }
            if (cursor != null) {
                cursor.close();
            }
        }
    } catch (Exception ex) {
        return "";
    }
    return fileName;
}

From source file:com.android.shell.BugreportReceiver.java

/**
 * Build {@link Intent} that can be used to share the given bugreport.
 *//*from   ww  w .  j  ava  2  s. c  o  m*/
private static Intent buildSendIntent(Context context, Uri bugreportUri, Uri screenshotUri) {
    final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("application/vnd.android.bugreport");

    intent.putExtra(Intent.EXTRA_SUBJECT, bugreportUri.getLastPathSegment());
    intent.putExtra(Intent.EXTRA_TEXT, SystemProperties.get("ro.build.description"));

    final ArrayList<Uri> attachments = Lists.newArrayList(bugreportUri, screenshotUri);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);

    final Account sendToAccount = findSendToAccount(context);
    if (sendToAccount != null) {
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { sendToAccount.name });
    }

    return intent;
}

From source file:org.kontalk.ui.ComposeMessage.java

public static Intent fromThreadUri(Context context, Uri threadUri) {
    String userId = threadUri.getLastPathSegment();
    Conversation conv = Conversation.loadFromUserId(context, userId);
    // not found - create new
    if (conv == null) {
        Intent ni = new Intent(context, ComposeMessage.class);
        ni.setAction(ComposeMessage.ACTION_VIEW_USERID);
        ni.setData(threadUri);/*from  www .ja  v  a2  s .  co  m*/
        return ni;
    }

    return fromConversation(context, conv);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java

public static DbObject from(Context context, Uri videoUri) throws IOException {
    // Query gallery for camera picture via
    // Android ContentResolver interface
    ContentResolver cr = context.getContentResolver();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;/*from w w  w  .j av a 2  s  .com*/
    long videoId = Long.parseLong(videoUri.getLastPathSegment());
    Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(cr, videoId,
            MediaStore.Video.Thumbnails.MINI_KIND, options);
    int targetSize = 200;
    int width = curThumb.getWidth();
    int height = curThumb.getHeight();
    int cropSize = Math.min(width, height);
    float scaleSize = ((float) targetSize) / cropSize;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleSize, scaleSize);
    curThumb = Bitmap.createBitmap(curThumb, 0, 0, width, height, matrix, true);
    JSONObject base = new JSONObject();
    String localIp = ContentCorral.getLocalIpAddress();
    if (localIp != null) {
        try {
            // TODO: Security breach hack?
            base.put(Contact.ATTR_LAN_IP, localIp);
            base.put(LOCAL_URI, videoUri.toString());
            base.put(MIME_TYPE, cr.getType(videoUri));
        } catch (JSONException e) {
            Log.e(TAG, "impossible json error possible!");
        }
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    curThumb.compress(Bitmap.CompressFormat.JPEG, 90, baos);
    byte[] data = baos.toByteArray();
    return from(base, data);
}

From source file:org.onebusaway.android.ui.QueryUtils.java

/**
 * Sets the given route and headsign and stop as a favorite, including checking to make sure that the
 * route has already been added to the local provider.  If this route/headsign should be marked
 * as a favorite for all stops, stopId should be null.
 *
 * @param routeUri Uri for the route to be added
 * @param headsign the headsign to be marked as favorite, along with the routeUri
 * @param stopId the stopId to be marked as a favorite, along with with route and headsign.  If
 *               this route/headsign should be marked for all stops, then stopId should be null
 * @param routeValues   content routeValues to be set for the route details (see ObaContract.RouteColumns)
 *                 (may be null)//from   w ww. j av  a  2 s. c  om
 * @param favorite true if this route/headsign should be marked as a favorite, false if it
 *                 should not
 */
public static void setFavoriteRouteAndHeadsign(Context context, Uri routeUri, String headsign, String stopId,
        ContentValues routeValues, boolean favorite) {
    if (routeValues == null) {
        routeValues = new ContentValues();
    }
    if (Application.get().getCurrentRegion() != null) {
        routeValues.put(ObaContract.Routes.REGION_ID, Application.get().getCurrentRegion().getId());
    }

    String routeId = routeUri.getLastPathSegment();

    // Make sure this route has been inserted into the routes table
    ObaContract.Routes.insertOrUpdate(context, routeId, routeValues, true);
    // Mark the combination of route and headsign as a favorite or not favorite
    ObaContract.RouteHeadsignFavorites.markAsFavorite(context, routeId, headsign, stopId, favorite);
}

From source file:com.android.emailcommon.utility.AttachmentUtilities.java

/**
 * @return mime-type for a {@link Uri}.// www . j a v  a  2s.com
 *    - Use {@link ContentResolver#getType} for a content: URI.
 *    - Use {@link #inferMimeType} for a file: URI.
 *    - Otherwise returns null.
 */
public static String inferMimeTypeForUri(Context context, Uri uri) {
    final String scheme = uri.getScheme();
    if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
        return context.getContentResolver().getType(uri);
    } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
        return inferMimeType(uri.getLastPathSegment(), "");
    } else {
        Log.e(Logging.LOG_TAG, "Unable to determine MIME type for uri=" + uri, new Error());
        return null;
    }
}

From source file:Main.java

/**
 * Get a uri's user-friendly display name
 * /*ww  w .j a v  a  2s  .  com*/
 * @param context the application context
 * @param uri     the uri to query
 * 
 * @return a user-friendly display name
 */
public static String getUriDisplayName(Context context, Uri uri) {
    String displayName = null;

    String scheme = uri.getScheme();

    if (scheme.startsWith("content")) {
        String[] proj = { OpenableColumns.DISPLAY_NAME };
        Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);

        if (cursor != null) {
            int columnIndex = cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME);
            cursor.moveToFirst();
            displayName = cursor.getString(columnIndex);

            cursor.close();
        }
    } else if (scheme.startsWith("file")) {
        displayName = uri.getLastPathSegment();
    }

    return displayName;
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java

/**
 * Does not touch db//from ww w  . j av  a2 s .c  om
 */
public static void cancelNotification(final Context context, final Uri uri) {
    if (uri != null)
        cancelNotification(context, Integer.parseInt(uri.getLastPathSegment()));
}