当前位置: 首页>>代码示例>>Java>>正文


Java ContentUris类代码示例

本文整理汇总了Java中android.content.ContentUris的典型用法代码示例。如果您正苦于以下问题:Java ContentUris类的具体用法?Java ContentUris怎么用?Java ContentUris使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentUris类属于android.content包,在下文中一共展示了ContentUris类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareEditContactIntentWithSipAddress

import android.content.ContentUris; //导入依赖的package包/类
public static Intent prepareEditContactIntentWithSipAddress(int id, String sipUri) {
	Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
	Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
	intent.setData(contactUri);
	
	ArrayList<ContentValues> data = new ArrayList<ContentValues>();
	ContentValues sipAddressRow = new ContentValues();
	sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
	sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
	data.add(sipAddressRow);
	intent.putParcelableArrayListExtra(Insert.DATA, data);
	
	return intent;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:15,代码来源:ApiElevenPlus.java

示例2: insert

import android.content.ContentUris; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
    final SQLiteDatabase db = mCardsDBHelper.getWritableDatabase();

    Uri returnUri = null;
    int match = sUriMatcher.match(uri);
    switch (match) {
        case TRANSACTIONS: // Since insert and query all has same url
            long transactionId = db.insert(DatabaseContract.TABLE_TRANSACTIONS, null, values);
            if (transactionId > 0) {
                returnUri = ContentUris.withAppendedId(DatabaseContract.CONTENT_URI, transactionId);
                getContext().getContentResolver().notifyChange(uri, null);
            } else {
                throw new SQLException("Can't create ID");
            }
            break;
        default:
            throw new UnsupportedOperationException("This URI is not supported");
    }
    return returnUri;
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:23,代码来源:TxProvider.java

示例3: insert

import android.content.ContentUris; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
    final int match = sUriMatcher.match(uri);
    long id;
    switch (match) {
        case MATCH_CODE_PLANT:
            id = mDbHelper.getWritableDatabase()
                    .insert(PlantEntry.TABLE_NAME, null, values);
            break;
        default:
            throw new IllegalArgumentException("Insert is not supported for " + uri);
    }
    if (id == -1) {
        Log.e(TAG, "Failed to insert row for " + uri);
        return null;
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return ContentUris.withAppendedId(uri, id);
}
 
开发者ID:laramartin,项目名称:android_firebase_green_thumb,代码行数:21,代码来源:PlantProvider.java

示例4: getSongCountForAlbumInt

import android.content.ContentUris; //导入依赖的package包/类
/**
 * @param context The {@link Context} to use.
 * @param id      The id of the album.
 * @return The song count for an album.
 */
public static final int getSongCountForAlbumInt(final Context context, final long id) {
    int songCount = 0;
    if (id == -1) {
        return songCount;
    }

    Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
    Cursor cursor = context.getContentResolver().query(uri,
            new String[]{AlbumColumns.NUMBER_OF_SONGS}, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            if (!cursor.isNull(0)) {
                songCount = cursor.getInt(0);
            }
        }
        cursor.close();
        cursor = null;
    }

    return songCount;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:28,代码来源:MusicUtils.java

示例5: onListItemClick

import android.content.ContentUris; //导入依赖的package包/类
/**
 * This method is called when the user clicks a note in the displayed list.
 *
 * This method handles incoming actions of either PICK (get data from the provider) or
 * GET_CONTENT (get or create data). If the incoming action is EDIT, this method sends a
 * new Intent to start NoteEditor.
 * @param l The ListView that contains the clicked item
 * @param v The View of the individual item
 * @param position The position of v in the displayed list
 * @param id The row ID of the clicked item
 */
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    // Constructs a new URI from the incoming URI and the row ID
    Uri uri = ContentUris.withAppendedId(getIntent().getData(), id);

    // Gets the action from the incoming Intent
    String action = getIntent().getAction();

    // Handles requests for note data
    if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {

        // Sets the result to return to the component that called this Activity. The
        // result contains the new URI
        setResult(RESULT_OK, new Intent().setData(uri));
    } else {

        // Sends out an Intent to start an Activity that can handle ACTION_EDIT. The
        // Intent's data is the note ID URI. The effect is to call NoteEdit.
        startActivity(new Intent(Intent.ACTION_EDIT, uri));
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:34,代码来源:NotesList.java

示例6: getLocalUri

import android.content.ContentUris; //导入依赖的package包/类
private String getLocalUri() {
    long destinationType = getLong(getColumnIndex(Downloads.Impl.COLUMN_DESTINATION));
    if (destinationType == Downloads.Impl.DESTINATION_FILE_URI ||
            destinationType == Downloads.Impl.DESTINATION_EXTERNAL ||
            destinationType == Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD) {
        String localPath = super.getString(getColumnIndex(COLUMN_LOCAL_FILENAME));
        if (localPath == null) {
            return null;
        }
        return Uri.fromFile(new File(localPath)).toString();
    }

    // return content URI for cache download
    long downloadId = getLong(getColumnIndex(Downloads.Impl._ID));
    return ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, downloadId).toString();
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:17,代码来源:DownloadManager.java

示例7: insert

import android.content.ContentUris; //导入依赖的package包/类
/**
 * @throws IOException if notebook with the same name already exists or some other failure.
 */
public static Book insert(Context context, Book book) throws IOException {
    if (doesExist(context, book.getName())) {
        throw new IOException("Can't insert notebook with the same name: " + book.getName());
    }

    ContentValues values = new ContentValues();
    BooksClient.toContentValues(values, book);
    Uri uri;
    try {
        uri = context.getContentResolver().insert(ProviderContract.Books.ContentUri.books(), values);
    } catch (Exception e) {
        throw ExceptionUtils.IOException(e, "Failed inserting book " + book.getName());
    }
    book.setId(ContentUris.parseId(uri));

    return book;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:21,代码来源:BooksClient.java

示例8: insert

import android.content.ContentUris; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
    SQLiteDatabase db = mDBHelper.getWritableDatabase();
    String tableName = getTableName(uri);
    long _id = db.insert(tableName, null, values);
    if (_id > 0) {
        Uri tableContentUri = getContentUri(uri);
        Uri insertedUri = ContentUris.withAppendedId(tableContentUri, _id);

        if (getContext() != null) {
            getContext().getContentResolver().notifyChange(uri, null);
        }

        return insertedUri;
    }

    return null;
}
 
开发者ID:agpyaephyo,项目名称:PADC-SFC-News,代码行数:20,代码来源:MMNewsProvider.java

示例9: query

import android.content.ContentUris; //导入依赖的package包/类
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] columns, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
    SQLiteDatabase db = sqlHelper.getReadableDatabase();
    int uriRequest = uriMatcher.match(uri);
    Cursor cursor;

    if (uriRequest == ContentContract.TASK){
        cursor = db.query(ContentContract.TABLE, columns, selection, selectionArgs, null, null, sortOrder);
    } else {
        long id = ContentUris.parseId(uri);
        String [] ids = {id + ""};
        cursor = db.query(ContentContract.TABLE, columns, ContentContract.COLUMN_ID + " = ?", ids, null, null, sortOrder);
    }

    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
开发者ID:marckregio,项目名称:maklib,代码行数:19,代码来源:ContentHandler.java

示例10: getReleaseDateForAlbum

import android.content.ContentUris; //导入依赖的package包/类
/**
 * @param context The {@link Context} to use.
 * @param id      The id of the album.
 * @return The release date for an album.
 */
public static final String getReleaseDateForAlbum(final Context context, final long id) {
    if (id == -1) {
        return null;
    }
    Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
    Cursor cursor = context.getContentResolver().query(uri, new String[]{
            AlbumColumns.FIRST_YEAR
    }, null, null, null);
    String releaseDate = null;
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            releaseDate = cursor.getString(0);
        }
        cursor.close();
        cursor = null;
    }
    return releaseDate;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:25,代码来源:MusicUtils.java

示例11: onContextItemSelected

import android.content.ContentUris; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
         info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }
    
    Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), info.id);

    switch (item.getItemId()) {
    case R.id.context_open:
        // Launch activity to view/edit the currently selected item
        startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
        return true;
    case R.id.context_delete:
        // Delete the note that the context menu is for
        getContentResolver().delete(noteUri, null, null);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}
 
开发者ID:firebase,项目名称:firebase-testlab-instr-lib,代码行数:26,代码来源:NotesList.java

示例12: query

import android.content.ContentUris; //导入依赖的package包/类
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
        @Nullable String[] selectionArgs, @Nullable String sortOrder) {
    final int code = MATCHER.match(uri);
    if (code == CODE_CHEESE_DIR || code == CODE_CHEESE_ITEM) {
        final Context context = getContext();
        if (context == null) {
            return null;
        }
        CheeseDao cheese = SampleDatabase.getInstance(context).cheese();
        final Cursor cursor;
        if (code == CODE_CHEESE_DIR) {
            cursor = cheese.selectAll();
        } else {
            cursor = cheese.selectById(ContentUris.parseId(uri));
        }
        cursor.setNotificationUri(context.getContentResolver(), uri);
        return cursor;
    } else {
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:24,代码来源:SampleContentProvider.java

示例13: insert

import android.content.ContentUris; //导入依赖的package包/类
public Uri insert(Uri uri, ContentValues values) {
    Uri newUri = null;
    int match = matcher.match(uri);
    SQLiteDatabase db = this.userInfoDb.getWritableDatabase();
    switch (match) {
        case 1000:
            long rowId = db.insert(UserInfoDb.TABLE_NAME, null, values);
            if (rowId > 0) {
                newUri = ContentUris.withAppendedId(URI_USERINFO, rowId);
                break;
            }
            break;
    }
    if (newUri != null) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return newUri;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:UserInfoContentProvider.java

示例14: handleImageOnKitKat

import android.content.ContentUris; //导入依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data){

    String imagePath=null;
    Uri uri=data.getData();
    if (DocumentsContract.isDocumentUri(getActivity(),uri)){
        //如果是 document 类型的 Uri,则通过document id处理
        String docId=DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())){
            String id=docId.split(":")[1];    //解析出数字格式的id
            String selection=MediaStore.Images.Media._ID+"="+id;
            imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
        }else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())){
            Uri contentUri= ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(docId));
            imagePath=getImagePath(contentUri,null);
        }
    }else if ("content".equalsIgnoreCase(uri.getScheme())){
        //如果是content类型的Uri 则使用普通方式处理
        imagePath=getImagePath(uri,null);
    }else if ("file".equalsIgnoreCase(uri.getScheme())){
        //如果是file类型的Uri,直接获取图片路径即可
        imagePath=uri.getPath();
    }
    displayImage(imagePath);      //根据图片路径显示图片
}
 
开发者ID:android-jian,项目名称:topnews,代码行数:27,代码来源:SettingFragment.java

示例15: get

import android.content.ContentUris; //导入依赖的package包/类
public static Alarm get(Context context, long id) {
  Alarm s = null;
  final Cursor c = context.getContentResolver().query(
      ContentUris.withAppendedId(AlarmClockProvider.ALARMS_URI, id),
      new String[] {
        AlarmClockProvider.AlarmEntry.TIME,
        AlarmClockProvider.AlarmEntry.ENABLED,
        AlarmClockProvider.AlarmEntry.NAME,
        AlarmClockProvider.AlarmEntry.DAY_OF_WEEK,
        AlarmClockProvider.AlarmEntry.NEXT_SNOOZE },
      null, null, null);
  if (c.moveToFirst())
    s = new Alarm(c);
  else
    s = new Alarm();
  c.close();
  return s;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:19,代码来源:DbUtil.java


注:本文中的android.content.ContentUris类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。