当前位置: 首页>>代码示例>>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;未经允许,请勿转载。