當前位置: 首頁>>代碼示例>>Java>>正文


Java Uri.getLastPathSegment方法代碼示例

本文整理匯總了Java中android.net.Uri.getLastPathSegment方法的典型用法代碼示例。如果您正苦於以下問題:Java Uri.getLastPathSegment方法的具體用法?Java Uri.getLastPathSegment怎麽用?Java Uri.getLastPathSegment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.Uri的用法示例。


在下文中一共展示了Uri.getLastPathSegment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEmail

import android.net.Uri; //導入方法依賴的package包/類
private String getEmail(Uri mContactUri) {

        String email = "";
        String id = mContactUri.getLastPathSegment();

        Cursor cursor = getContentResolver().query(
                ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?",
                new String[] { id},
                null
        );

        int emailIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);

        if(cursor.moveToFirst()){
            email = cursor.getString(emailIdx);
        }

        return email;

    }
 
開發者ID:micromasterandroid,項目名稱:androidbeginners-Lesson3,代碼行數:23,代碼來源:MainActivity.java

示例2: hasGlobalSearchIntent

import android.net.Uri; //導入方法依賴的package包/類
/**
 * Check if there is a global search intent. If there is, load that video.
 */
private boolean hasGlobalSearchIntent() {
    Intent intent = getActivity().getIntent();
    String intentAction = intent.getAction();
    String globalSearch = getString(R.string.global_search);

    if (globalSearch.equalsIgnoreCase(intentAction)) {
        Uri intentData = intent.getData();
        String videoId = intentData.getLastPathSegment();

        Bundle args = new Bundle();
        args.putString(VideoContract.VideoEntry._ID, videoId);
        getLoaderManager().initLoader(mGlobalSearchVideoId++, args, this);
        return true;
    }
    return false;
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:20,代碼來源:VideoDetailsFragment.java

示例3: addLink

import android.net.Uri; //導入方法依賴的package包/類
private void addLink(Uri uri, String title, boolean append)
{
    if ((title == null) || (title.length() == 0))
        title = uri.getLastPathSegment();

    String url = uri.toString();
    String linkText = String.format(LINK_TEMPLATE, title, url);

    if (append)
        textView.append(linkText);

    else
    {
        Editable editable = textView.getEditableText();
        int position = textView.getSelectionStart();
        editable.insert(position, linkText);
    }

    loadMarkdown();
}
 
開發者ID:billthefarmer,項目名稱:diary,代碼行數:21,代碼來源:Diary.java

示例4: getRepo

import android.net.Uri; //導入方法依賴的package包/類
@Nullable private static Intent getRepo(@NonNull Context context, @NonNull Uri uri) {
    List<String> segments = uri.getPathSegments();
    if (segments == null || segments.size() < 2 || segments.size() > 3) return null;
    String owner = segments.get(0);
    String repoName = segments.get(1);
    if (!InputHelper.isEmpty(repoName)) {
        repoName = repoName.replace(".git", "");
    }
    if (segments.size() == 3) {
        String lastPath = uri.getLastPathSegment();
        if ("network".equalsIgnoreCase(lastPath)) {
            return RepoDetailActivity.createIntent(context, repoName, owner, Tab.CODE, 3);
        } else if ("stargazers".equalsIgnoreCase(lastPath)) {
            return RepoDetailActivity.createIntent(context, repoName, owner, Tab.CODE, 2);
        } else if ("watchers".equalsIgnoreCase(lastPath)) {
            return RepoDetailActivity.createIntent(context, repoName, owner, Tab.CODE, 1);
        } else {
            return null;
        }
    } else {
        return RepoDetailActivity.createIntent(context, repoName, owner);
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:24,代碼來源:SchemeParser.java

示例5: update

import android.net.Uri; //導入方法依賴的package包/類
/**
 * Actualiza registros de la tabla de clientes
 * @param uri uri del content provider.
 * @param values ContentValues con los valores a actualizar
 * @param selection filtro de actualización.
 * @param selectionArgs argumentos del filtro
 * @return número de registros actualizados por la operación
 */
@Override
public int update(Uri uri, ContentValues values,
                  String selection, String[] selectionArgs) {

    int cont;

    //Si es una consulta a un ID concreto construimos el WHERE
    String where = selection;
    if(uriMatcher.match(uri) == CLIENTES_ID){
        where = "_id=" + uri.getLastPathSegment();
    }

    SQLiteDatabase db = clidbh.getWritableDatabase();

    cont = db.update(ClientesDBContract.TABLA_CLIENTES, values, where, selectionArgs);

    return cont;
}
 
開發者ID:gothalo,項目名稱:Android-2017,代碼行數:27,代碼來源:ClientesProvider.java

示例6: updateIndexedShortcuts

import android.net.Uri; //導入方法依賴的package包/類
public void updateIndexedShortcuts(Cursor cursor) {
    mShortcutsCursor = cursor;
    uriColumnIndex = mShortcutsCursor.getColumnIndex(ShortcutDbAdapter.KEY_PATH);
    nameColumnIndex = mShortcutsCursor.getColumnIndex(ShortcutDbAdapter.KEY_NAME);
    friendlyUriColumnIndex = mShortcutsCursor.getColumnIndex(ShortcutDbAdapter.KEY_FRIENDLY_URI);
    mIndexedShortcuts = new ArrayList<ShortcutDbAdapter.Shortcut>();
    if(mShortcutsCursor.getCount()>0){
        mShortcutsCursor.moveToFirst();
        do{
            String name = mShortcutsCursor.getString(nameColumnIndex);
            Uri uri = Uri.parse(mShortcutsCursor.getString(uriColumnIndex));
            String friendlyUri = mShortcutsCursor.getString(friendlyUriColumnIndex);
            if(name==null||name.isEmpty()) {
                name = uri.getLastPathSegment();
            }
            mIndexedShortcuts.add(new ShortcutDbAdapter.Shortcut(name, uri.toString(),friendlyUri));
        }while(mShortcutsCursor.moveToNext());
    }
    resetData();
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:21,代碼來源:RootFragmentAdapter.java

示例7: delete

import android.net.Uri; //導入方法依賴的package包/類
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    int uriType = sURIMatcher.match(uri);
    SQLiteDatabase sqlDB = _database.getWritableDatabase();
    int rowsDeleted = 0;
    switch (uriType) {

        case FEEDS:
            rowsDeleted = sqlDB.delete(FeedContract.Feeds.TABLE_NAME, selection, selectionArgs);
            break;

        case FEED_ID:
            String id = uri.getLastPathSegment();
            if (TextUtils.isEmpty(selection)) {
                rowsDeleted = sqlDB.delete(
                        FeedContract.Feeds.TABLE_NAME,
                        FeedContract.Feeds._ID + "=" + id,
                        null
                );
            } else {
                rowsDeleted = sqlDB.delete(
                        FeedContract.Feeds.TABLE_NAME,
                        FeedContract.Feeds._ID + "=" + id + " and " + selection,
                        selectionArgs
                );
            }
            break;

        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsDeleted;
}
 
開發者ID:no-go,項目名稱:AnotherRSS,代碼行數:35,代碼來源:FeedContentProvider.java

示例8: internalDelete

import android.net.Uri; //導入方法依賴的package包/類
public int internalDelete(Uri uri, String selection, String[] selectionArgs) {
    String data = uri.getLastPathSegment();
    String whereClause;
    String[] whereArgs;
    SQLiteDatabase db = mDbHolder.get();
    if(DBG) Log.d(TAG, "Delete request with URI " + uri.toString());
    try {
        switch (sUriMatcher.match(uri)) {
            case MOVIE:
                return db.delete(ScraperTables.MOVIE_TABLE_NAME, selection,
                        selectionArgs);
            case MOVIE_ID:
                whereClause = ScraperStore.Movie.ID + "=?";
                whereArgs = new String[] {data};
                return db.delete(ScraperTables.MOVIE_TABLE_NAME, whereClause, whereArgs);
            case EPISODE:
                return db.delete(ScraperTables.EPISODE_TABLE_NAME, selection,
                        selectionArgs);
            case EPISODE_ID:
                whereClause = ScraperStore.Episode.ID + "=?";
                whereArgs = new String[] {data};
                return db.delete(ScraperTables.EPISODE_TABLE_NAME, whereClause, whereArgs);
            default:
                throw new IllegalArgumentException("Unknown URI " + uri);
        }
    } catch (SQLiteConstraintException e) {
        Log.d (TAG, "Delete Failed selection:" + selection + " selectionArgs:" + Arrays.toString(selectionArgs));
        return 0;
    }
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:31,代碼來源:ScraperProvider.java

示例9: findFileName

import android.net.Uri; //導入方法依賴的package包/類
private static String findFileName(Context context, Uri uri) {
    String fileName = uri.getLastPathSegment();
    try {
        String scheme = uri.getScheme();
        if (scheme.equals("file")) {
            fileName = uri.getLastPathSegment();
        } else if (scheme.equals("content")) {
            String[] proj = {MediaStore.Images.Media.TITLE};

            Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
            if (cursor != null && cursor.getCount() != 0) {
                int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.TITLE);
                cursor.moveToFirst();
                fileName = cursor.getString(columnIndex);
            }

            if (cursor != null) {
                cursor.close();
            }
        }

    } catch (Exception ignored) {

    }

    return fileName;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:28,代碼來源:DocumentUploadTask.java

示例10: update

import android.net.Uri; //導入方法依賴的package包/類
@Override
public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    String table;
    switch (sUriMatcher.match(uri)) {
        case EPISODE_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case EPISODE:
            table = ScraperTables.EPISODE_TABLE_NAME;
            break;

        case SHOW_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case SHOW:
        case SHOW_NAME:
            table = ScraperTables.SHOW_TABLE_NAME;
            break;

        case MOVIE_ID:
            selection = "_id=?";
            selectionArgs = new String[] { uri.getLastPathSegment() };
            //$FALL-THROUGH$
        case MOVIE:
            table = ScraperTables.MOVIE_TABLE_NAME;
            break;

        case MOVIE_BACKDROPS:
            table = ScraperTables.MOVIE_BACKDROPS_TABLE_NAME;
            break;
        case MOVIE_POSTERS:
            table = ScraperTables.MOVIE_POSTERS_TABLE_NAME;
            break;
        case SHOW_BACKDROPS:
            table = ScraperTables.SHOW_BACKDROPS_TABLE_NAME;
            break;
        case SHOW_POSTERS:
            table = ScraperTables.SHOW_POSTERS_TABLE_NAME;
            break;

        default:
            throw new IllegalArgumentException("URI not supported in update(): " + uri);
    }
    SQLiteDatabase db = mDbHolder.get();
    int updated = db.update(table, values,
            selection, selectionArgs);
    if (updated > 0 && !db.inTransaction()) {
        mCr.notifyChange(uri, null);
        mCr.notifyChange(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, null);
    }
    return updated;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:56,代碼來源:ScraperProvider.java

示例11: update

import android.net.Uri; //導入方法依賴的package包/類
/**
     * Implement this to handle requests to update one or more rows.
     * The implementation should update all rows matching the selection
     * to set the columns according to the provided values map.
     * As a courtesy, call {@link ContentResolver#notifyChange(Uri, ContentObserver) notifyChange()}
     * after updating.
     * This method can be called from multiple threads, as described in
     * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
     * and Threads</a>.
     *
     * @param uri           The URI to query. This can potentially have a record ID if this
     *                      is an update request for a specific record.
     * @param values        A set of column_name/value pairs to update in the database.
     *                      This must not be {@code null}.
     * @param selection     An optional filter to match rows to update.
     * @param selectionArgs
     * @return the number of rows affected.
     */
    @Override
    public int update(@NonNull Uri uri, @NonNull ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
        String table;
        boolean isID = false;
        switch(sUriMatcher.match(uri)) {
            case activities_ID:
                isID = true;
                table = ActivityDiaryContract.DiaryActivity.TABLE_NAME;
                break;
            case diary_ID:
                isID = true;
            case diary:
                table = ActivityDiaryContract.Diary.TABLE_NAME;
                break;
            case diary_image:
                table = ActivityDiaryContract.DiaryImage.TABLE_NAME;
                break;
            case conditions_ID:
                isID = true;
//                table = ActivityDiaryContract.Condition.TABLE_NAME;
//                break;
            default:
                throw new IllegalArgumentException(
                        "Unsupported URI for update: " + uri);
        }
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        if(isID) {
            if (selection != null) {
                selection = selection + " AND ";
            } else {
                selection = "";
            }
            selection = selection + "_id=" + uri.getLastPathSegment();
        }

        int upds = db.update(table,
                values,
                selection,
                selectionArgs);
        if(upds > 0) {
            getContext().
                    getContentResolver().
                    notifyChange(uri, null);

        }else if(isID) {
            throw new SQLException(
                    "Problem while updating uri: " + uri);
        }
        return upds;
    }
 
開發者ID:ramack,項目名稱:ActivityDiary,代碼行數:69,代碼來源:ActivityDiaryContentProvider.java

示例12: createCalendar

import android.net.Uri; //導入方法依賴的package包/類
@SuppressWarnings("MissingPermission") // already requested in calling method
 public String createCalendar(String calendarName, String calendarColor) {
     try {
         // don't create if it already exists
         Uri evuri = CalendarContract.Calendars.CONTENT_URI;
         final ContentResolver contentResolver = cordova.getActivity().getContentResolver();
         Cursor result = contentResolver.query(evuri, new String[]{CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}, null, null, null);
         if (result != null) {
             while (result.moveToNext()) {
                 if (result.getString(1).equals(calendarName) || result.getString(2).equals(calendarName)) {
                     result.close();
                     return null;
                 }
             }
             result.close();
         }

         // doesn't exist yet, so create
         Uri calUri = CalendarContract.Calendars.CONTENT_URI;
         ContentValues cv = new ContentValues();
         cv.put(CalendarContract.Calendars.ACCOUNT_NAME, "AccountName");
         cv.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
         cv.put(CalendarContract.Calendars.NAME, calendarName);
         cv.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, calendarName);
         if (calendarColor != null) {
             cv.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.parseColor(calendarColor));
         }
         cv.put(CalendarContract.Calendars.VISIBLE, 1);
cv.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, "AccountName" );
         cv.put(CalendarContract.Calendars.SYNC_EVENTS, 0);

         calUri = calUri.buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "AccountName")
                 .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
                 .build();

         Uri created = contentResolver.insert(calUri, cv);
         if (created != null) {
             return created.getLastPathSegment();
         }
     } catch (Exception e) {
         Log.e(LOG_TAG, "Creating calendar failed.", e);
     }
     return null;
 }
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:48,代碼來源:AbstractCalendarAccessor.java

示例13: update

import android.net.Uri; //導入方法依賴的package包/類
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs){
    db = tOpenHelper.getWritableDatabase();
    int count = 0;
    String idStr, where;
    switch(sUriMatcher.match(uri)) {
        case ENTRY_LIST:
            count = db.update(TodoEntry.TABLE_NAME, values, selection, selectionArgs);
            break;
        case ENTRY_ID:
            idStr = uri.getLastPathSegment();
            where = TodoEntry._ID + " = " + idStr;
            if (!TextUtils.isEmpty(selection)) {
                where += " AND " + selection;
            }
            count = db.update(TodoEntry.TABLE_NAME, values, where,
                    selectionArgs);
            break;
        case LABEL_LIST:
            count = db.update(TodoLabel.TABLE_NAME, values, selection, selectionArgs);
            break;
        case LABEL_ID:
            idStr = uri.getLastPathSegment();
            where = TodoLabel._ID + " = " + idStr;
            if (!TextUtils.isEmpty(selection)) {
                where += " AND " + selection;
            }
            count = db.update(TodoLabel.TABLE_NAME, values, where,
                    selectionArgs);
            break;
        case NOTIFICATION_LIST:
            count = db.update(TodoNotification.TABLE_NAME, values, selection, selectionArgs);
            break;
        case NOTIFICATION_ID:
            idStr = uri.getLastPathSegment();
            where = TodoNotification._ID + " = " + idStr;
            if (!TextUtils.isEmpty(selection)) {
                where += " AND " + selection;
            }
            count = db.update(TodoNotification.TABLE_NAME, values, where,
                    selectionArgs);
            break;
        default:
            throw new IllegalArgumentException("Unsupported URI: " + uri);
    }
    if (count > 0){
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return count;
}
 
開發者ID:danlls,項目名稱:Todule-android,代碼行數:50,代碼來源:ToduleProvider.java

示例14: toPath

import android.net.Uri; //導入方法依賴的package包/類
/**
 * 從第三方文件選擇器獲取路徑。
 * 參見:http://blog.csdn.net/zbjdsbj/article/details/42387551
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String toPath(Context context, Uri uri) {
    if (uri == null) {
        LogUtils.verbose("uri is null");
        return "";
    }
    LogUtils.verbose("uri: " + uri.toString());
    String path = uri.getPath();
    String scheme = uri.getScheme();
    String authority = uri.getAuthority();
    //是否是4.4及以上版本
    boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        String docId = DocumentsContract.getDocumentId(uri);
        String[] split = docId.split(":");
        String type = split[0];
        Uri contentUri = null;
        switch (authority) {
            // ExternalStorageProvider
            case "com.android.externalstorage.documents":
                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
                break;
            // DownloadsProvider
            case "com.android.providers.downloads.documents":
                contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
                return _queryPathFromMediaStore(context, contentUri, null, null);
            // MediaProvider
            case "com.android.providers.media.documents":
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                String selection = "_id=?";
                String[] selectionArgs = new String[]{split[1]};
                return _queryPathFromMediaStore(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else {
        if ("content".equalsIgnoreCase(scheme)) {
            // Return the remote address
            if (authority.equals("com.google.android.apps.photos.content")) {
                return uri.getLastPathSegment();
            }
            return _queryPathFromMediaStore(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(scheme)) {
            return uri.getPath();
        }
    }
    LogUtils.verbose("uri to path: " + path);
    return path;
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:66,代碼來源:ConvertUtils.java

示例15: delete

import android.net.Uri; //導入方法依賴的package包/類
@Override
public synchronized int delete(Uri uri, String selection,
        String[] selectionArgs) {
    // Opens the database object in "write" mode.
    SQLiteDatabase db = mHistoryHelper.getWritableDatabase();
    String finalWhere;

    int count;

    // Does the delete based on the incoming URI pattern.
    switch (URI_MATCHER.match(uri)) {
    /*
     * If the incoming pattern matches the general pattern for history
     * items, does a delete based on the incoming "where" columns and
     * arguments.
     */
    case URI_HISTORY:
        count = db.delete(HistoryContract.TABLE_NAME, selection,
                selectionArgs);
        break;// URI_HISTORY

    /*
     * If the incoming URI matches a single note ID, does the delete based
     * on the incoming data, but modifies the where clause to restrict it to
     * the particular history item ID.
     */
    case URI_HISTORY_ID:
        /*
         * Starts a final WHERE clause by restricting it to the desired
         * history item ID.
         */
        finalWhere = DbUtils.SQLITE_FTS_COLUMN_ROW_ID + " = "
                + uri.getLastPathSegment();

        /*
         * If there were additional selection criteria, append them to the
         * final WHERE clause
         */
        if (selection != null)
            finalWhere = finalWhere + " AND " + selection;

        // Performs the delete.
        count = db.delete(HistoryContract.TABLE_NAME, finalWhere,
                selectionArgs);
        break;// URI_HISTORY_ID

    // If the incoming pattern is invalid, throws an exception.
    default:
        throw new IllegalArgumentException("UNKNOWN URI " + uri);
    }

    /*
     * Gets a handle to the content resolver object for the current context,
     * and notifies it that the incoming URI changed. The object passes this
     * along to the resolver framework, and observers that have registered
     * themselves for the provider are notified.
     */
    getContext().getContentResolver().notifyChange(uri, null);

    // Returns the number of rows deleted.
    return count;
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:63,代碼來源:HistoryProvider.java


注:本文中的android.net.Uri.getLastPathSegment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。