當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。