本文整理匯總了Java中android.database.Cursor.getColumnIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getColumnIndex方法的具體用法?Java Cursor.getColumnIndex怎麽用?Java Cursor.getColumnIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.getColumnIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveUri
import android.database.Cursor; //導入方法依賴的package包/類
static private Uri resolveUri(Uri uri) {
Activity activity = org.qtproject.qt5.android.QtNative.activity();
String[] columns = { MediaStore.Video.Media.DATA };
Cursor cursor = activity.getContentResolver().query(uri, columns, null, null, null);
if (cursor == null) {
Log.d(TAG,"Query failed");
return Uri.parse("");
}
cursor.moveToFirst();
int columnIndex;
columnIndex = cursor.getColumnIndex(columns[0]);
String path = cursor.getString(columnIndex);
cursor.close();
return Uri.fromParts("file",path,"");
}
示例2: validateCurrentRecord
import android.database.Cursor; //導入方法依賴的package包/類
/**
* This method iterates through a set of expected values and makes various assertions that
* will pass if our app is functioning properly.
*
* @param error Message when an error occurs
* @param valueCursor The Cursor containing the actual values received from an arbitrary query
* @param expectedValues The values we expect to receive in valueCursor
*/
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
for (Map.Entry<String, Object> entry : valueSet) {
String columnName = entry.getKey();
int index = valueCursor.getColumnIndex(columnName);
/* Test to see if the column is contained within the cursor */
String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
assertFalse(columnNotFoundError, index == -1);
/* Test to see if the expected value equals the actual value (from the Cursor) */
String expectedValue = entry.getValue().toString();
String actualValue = valueCursor.getString(index);
String valuesDontMatchError = "Actual value '" + actualValue
+ "' did not match the expected value '" + expectedValue + "'. "
+ error;
assertEquals(valuesDontMatchError,
expectedValue,
actualValue);
}
}
示例3: updateUI
import android.database.Cursor; //導入方法依賴的package包/類
private void updateUI() {
ArrayList<String> objList = new ArrayList<>();
ArrayList<Integer> numList = new ArrayList<>();
SQLiteDatabase db = mHelper.getReadableDatabase();
Cursor cursor = db.query(TaskContract.TaskEntry.TABLE,
new String[]{TaskContract.TaskEntry._ID, TaskContract.TaskEntry.COL_TASK_TITLE, TaskContract.TaskEntry.COL_NUM_TITLE},
null, null, null, null, null);
while (cursor.moveToNext()) {
int idx = cursor.getColumnIndex(TaskContract.TaskEntry.COL_TASK_TITLE);
int idx_num = cursor.getColumnIndex(TaskContract.TaskEntry.COL_NUM_TITLE);
objList.add(cursor.getString(idx));
numList.add(cursor.getInt(idx_num));
}
mListAdapter.setData(objList, numList);
cursor.close();
db.close();
if (objList.size() > 0) {
instructionTextView.setVisibility(View.INVISIBLE);
}else {
instructionTextView.setVisibility(View.VISIBLE);
}
}
示例4: onActivityResult
import android.database.Cursor; //導入方法依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Uri selectedFile = data.getData();
if (selectedFile != null) {
mService.setUri(selectedFile);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(getApplicationContext(), selectedFile);
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long duration = Long.parseLong(time );
int size = 0;
Cursor cursor = getContentResolver()
.query(selectedFile, null, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
size = cursor.getColumnIndex(OpenableColumns.SIZE);
if (!cursor.isNull(size)) {
// Technically the column stores an int, but cursor.getString()
// will do the conversion automatically.
size = cursor.getInt(size);
}
}
mService.mSyncPlayClient.set_file(duration / 1000, size, getFileName(selectedFile));
mService.preparePlayer();
} else if (resultCode != REQUEST_INVITE) {
Toast.makeText(this, "Error loading the file.", Toast.LENGTH_SHORT)
.show();
}
}
}
}
示例5: getHighlightById
import android.database.Cursor; //導入方法依賴的package包/類
public Highlight getHighlightById(int highlightId, int pageId, Context mContext, int bookId) {
Cursor c = getReadableDatabase().query(UserDataDBContract.HighlightEntry.TABLE_NAME,
new String[]{
UserDataDBContract.HighlightEntry.COLUMN_CLASS_NAME,
UserDataDBContract.HighlightEntry.COLUMN_CONTAINER_ELEMENT_ID,
UserDataDBContract.HighlightEntry.COLUMN_TEXT,
UserDataDBContract.HighlightEntry.COLUMN_NAME_TIME_STAMP,
UserDataDBContract.HighlightEntry.COLUMN_NOTE_TEXT
},
UserDataDBContract.HighlightEntry.COLUMN_NAME_BOOK_ID + "=?" + " and " +
UserDataDBContract.HighlightEntry.COLUMN_NAME_PAGE_ID + "=?" + " and " +
UserDataDBContract.HighlightEntry.COLUMN_NAME_HIGHLIGHT_ID + "=?",
new String[]{String.valueOf(bookId), String.valueOf(pageId), String.valueOf(highlightId)},
null,
null,
UserDataDBContract.BookmarkEntry.COLUMN_NAME_PAGE_ID
);
final int INDEX_CLASS_NAME = c.getColumnIndex(UserDataDBContract.HighlightEntry.COLUMN_CLASS_NAME);
final int INDEX_ELEMENT_ID = c.getColumnIndex(UserDataDBContract.HighlightEntry.COLUMN_CONTAINER_ELEMENT_ID);
final int INDEX_TEXT = c.getColumnIndex(UserDataDBContract.HighlightEntry.COLUMN_TEXT);
final int INDEX_NOTE_TEXT = c.getColumnIndex(UserDataDBContract.HighlightEntry.COLUMN_NOTE_TEXT);
final int INDEX_TIME_STAMP = c.getColumnIndex(UserDataDBContract.HighlightEntry.COLUMN_NAME_TIME_STAMP);
BookDatabaseHelper bookDatabaseHelper = BookDatabaseHelper.getInstance(mContext, bookId);
Highlight highlight = null;
if (c.moveToFirst()) {
PageInfo pageInfo = bookDatabaseHelper.getPageInfoByPageId(pageId);
String className = c.getString(INDEX_CLASS_NAME);
int elementId = c.getInt(INDEX_ELEMENT_ID);
String timeStamp = c.getString(INDEX_TIME_STAMP);
String text = c.getString(INDEX_TEXT);
String noteText = c.getString(INDEX_NOTE_TEXT);
highlight = new Highlight(text, highlightId, className, elementId, timeStamp, pageInfo, bookId, bookDatabaseHelper.getParentTitle(pageId), noteText);
}
c.close();
return highlight;
}
示例6: getImageFile
import android.database.Cursor; //導入方法依賴的package包/類
public static File getImageFile(Context context, Uri selectedImage) {
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String imagePath = cursor.getString(columnIndex);
cursor.close();
return new File(imagePath);
}
示例7: query
import android.database.Cursor; //導入方法依賴的package包/類
private List<MediaStoreData> query(Uri contentUri, String[] projection, String sortByCol,
String idCol, String dateTakenCol, String dateModifiedCol, String mimeTypeCol,
String orientationCol, MediaStoreData.Type type) {
final List<MediaStoreData> data = new ArrayList<MediaStoreData>();
Cursor cursor = getContext().getContentResolver()
.query(contentUri, projection, null, null, sortByCol + " DESC");
if (cursor == null) {
return data;
}
try {
final int idColNum = cursor.getColumnIndexOrThrow(idCol);
final int dateTakenColNum = cursor.getColumnIndexOrThrow(dateTakenCol);
final int dateModifiedColNum = cursor.getColumnIndexOrThrow(dateModifiedCol);
final int mimeTypeColNum = cursor.getColumnIndex(mimeTypeCol);
final int orientationColNum = cursor.getColumnIndexOrThrow(orientationCol);
while (cursor.moveToNext()) {
long id = cursor.getLong(idColNum);
long dateTaken = cursor.getLong(dateTakenColNum);
String mimeType = cursor.getString(mimeTypeColNum);
long dateModified = cursor.getLong(dateModifiedColNum);
int orientation = cursor.getInt(orientationColNum);
data.add(new MediaStoreData(id, Uri.withAppendedPath(contentUri, Long.toString(id)),
mimeType, dateTaken, dateModified, orientation, type));
}
} finally {
cursor.close();
}
return data;
}
示例8: lastModifiedDateForCursor
import android.database.Cursor; //導入方法依賴的package包/類
protected Long lastModifiedDateForCursor(Cursor cursor) {
int columnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED);
if (columnIndex == -1) {
columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED);
}
if (columnIndex != -1) {
String dateStr = cursor.getString(columnIndex);
if (dateStr != null) {
return Long.parseLong(dateStr);
}
}
return null;
}
示例9: getContactNameByPhoneNumber
import android.database.Cursor; //導入方法依賴的package包/類
public static String getContactNameByPhoneNumber(Context context, String address) {
String[] projection = {ContactsContract.PhoneLookup.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
// 將自己添加到 msPeers 中
Cursor cursor = context.getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection,
ContactsContract.CommonDataKinds.Phone.NUMBER + " = '"
+ address + "'", null,null);
if (cursor == null) {
return null;
}
try {
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
// 取得聯係人名字
int nameFieldColumnIndex = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
String name = cursor.getString(nameFieldColumnIndex);
return name;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
cursor = null;
}
return null;
}
示例10: getContactsList
import android.database.Cursor; //導入方法依賴的package包/類
/**
* 同步返回聯係人列表
*/
public static List<ContactsInfo> getContactsList(Context context) {
//檢查權限
if (Build.VERSION.SDK_INT >= 23) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
return new ArrayList<>();
}
}
final ContentResolver contentResolver = context.getContentResolver();
Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, new String[]{"_id"}, null, null, null);
List<ContactsInfo> contactsInfos = new ArrayList<>();
if (cursor != null) {
//枚舉所有聯係人的id
if (cursor.getCount() > 0) {
L.w("聯係人總數量:" + cursor.getCount()); //就是聯係人的總數
int count = 0;
if (cursor.moveToFirst()) {
do {
int contactIdIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);//獲取 id 所在列的索引
String contactId = cursor.getString(contactIdIndex);//聯係人id
final List<String> phones = getData1(contentResolver, contactId, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
if (phones.isEmpty()) {
continue;
} else {
String name;
final List<String> names = getData1(contentResolver, contactId, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
if (names.isEmpty()) {
name = phones.get(0);
} else {
name = names.get(0);
}
//相同聯係人的不同手機號碼視為不同的聯係人
for (String phone : phones) {
// 去除非手機號
if (!RegexUtils.isMobileExact(StringUtil.removeBlanks(phone))) {
continue;
}
ContactsInfo io = new ContactsInfo();
io.contactId = contactId;
io.name = name;
io.phone = StringUtil.removeBlanks(phone);
io.letter = String.valueOf(Pinyin.toPinyin(name.charAt(0)).toUpperCase().charAt(0));
contactsInfos.add(io);
}
}
// L.e("-------------------------" + count + "----------------------");
// L.w("聯係人ID:" + contactId);
// final String name = getData1(contentResolver, contactId, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
// L.w("聯係人名稱:" + Pinyin.toPinyin(name.charAt(0)).toUpperCase().charAt(0) + " " + name);
// L.w("聯係人電話:" + getData1(contentResolver, contactId, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE));
// logData(contentResolver, contactId);
// count++;
} while (cursor.moveToNext());
}
}
cursor.close();
}
return contactsInfos;
}
示例11: ContactCursorWrapper
import android.database.Cursor; //導入方法依賴的package包/類
ContactCursorWrapper(Cursor cursor) {
super(cursor);
cursor.moveToFirst();
ID = cursor.getColumnIndex(ContactTable.Column.ID);
NAME = getColumnIndex(ContactTable.Column.NAME);
TYPE = getColumnIndex(ContactTable.Column.TYPE);
}
示例12: onLoadFinished
import android.database.Cursor; //導入方法依賴的package包/類
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
if (cursorLoader.getId()==SEASONS_LOADER_ID) {
//TODO:
// CAUTION: we get an update here each time a single episode resume point is changed...
// Basic solution: fill the season rows only the first time, i.e. guess it does not change over
// time, which is true with the current feature set at least...
cursor.moveToFirst();
final int seasonNumberColumn = cursor.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_E_SEASON);
mSeasonAdapters = new SparseArray<CursorObjectAdapter>();
// Build one row for each season
while (!cursor.isAfterLast()) {
int seasonNumber = cursor.getInt(seasonNumberColumn);
CursorObjectAdapter seasonAdapter = new CursorObjectAdapter(new PosterImageCardPresenter(getActivity(), PosterImageCardPresenter.EpisodeDisplayMode.FOR_SEASON_LIST));
seasonAdapter.setMapper(new CompatibleCursorMapperConverter(new VideoCursorMapper()));
mSeasonAdapters.put(seasonNumber, seasonAdapter);
mRowsAdapter.add(new ListRow(seasonNumber,
new HeaderItem(seasonNumber, "Season " + seasonNumber),
seasonAdapter));
getLoaderManager().restartLoader(seasonNumber, null, this);
cursor.moveToNext();
}
cursor.close();
}
else {
// We got the list of episode for one season, load it
mSeasonAdapters.get(cursorLoader.getId()).changeCursor(cursor);
}
}
示例13: getRealPathFromURI
import android.database.Cursor; //導入方法依賴的package包/類
public String getRealPathFromURI(Context context, String contentURI) {
Uri contentUri = Uri.parse(contentURI);
Cursor cursor = context.getContentResolver().query(contentUri, null, null, null, null);
if (cursor == null) {
return contentUri.getPath();
} else {
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(index);
}
}
示例14: bindColumns
import android.database.Cursor; //導入方法依賴的package包/類
@Override
public void bindColumns(Cursor c) {
mIdColumn = c.getColumnIndex(BaseColumns._ID);
mScraperTypeColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_MEDIA_SCRAPER_TYPE);
mNameColumn = c.getColumnIndex(VideoLoader.COLUMN_NAME);
// Episodes stuff
mEpisodeIdColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_EPISODE_ID);
mEpisodeSeasonColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_E_SEASON);
mEpisodeNumberColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_E_EPISODE);
mEpisodeNameColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_E_NAME);
// Movies stuff
mMovieIdColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_MOVIE_ID);
// Movies/Episodes common stuff
mBackdropUrlColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_BACKDROP_LARGE_URL);
mBackdropFileColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_BACKDROP_LARGE_FILE);
mDateColumn = c.getColumnIndex(VideoLoader.COLUMN_DATE);
mRatingColumn = c.getColumnIndex(VideoLoader.COLUMN_RATING);
mPlotColumn = c.getColumnIndex(VideoLoader.COLUMN_PLOT);
mShowNameColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_TITLE);
mPathColumn = c.getColumnIndex(VideoStore.MediaColumns.DATA);
mPosterPathColumn = c.getColumnIndex(VideoLoader.COLUMN_COVER_PATH);
mDurationColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.DURATION);
mResumeColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.BOOKMARK);
mBookmarkColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_BOOKMARK);
m3dColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_VIDEO_STEREO);
mGuessedDefinitionColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_VIDEO_DEFINITION);
// Trakt
mTraktSeenColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_TRAKT_SEEN);
mTraktLibraryColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_TRAKT_LIBRARY);
// User can show/hide some files
mUserHiddenColumn = c.getColumnIndex(VideoStore.Video.VideoColumns.ARCHOS_HIDDEN_BY_USER);
}
示例15: queryFiles
import android.database.Cursor; //導入方法依賴的package包/類
private void queryFiles() {
String[] projection = new String[]{MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.SIZE
};
// cache
String bookpath = FileUtils.createRootPath(AppUtils.getAppContext());
// 查詢後綴名為txt與pdf,並且不位於項目緩存中的文檔
Cursor cursor = getContentResolver().query(
Uri.parse("content://media/external/file"),
projection,
MediaStore.Files.FileColumns.DATA + " not like ? and ("
+ MediaStore.Files.FileColumns.DATA + " like ? or "
+ MediaStore.Files.FileColumns.DATA + " like ? or "
+ MediaStore.Files.FileColumns.DATA + " like ? or "
+ MediaStore.Files.FileColumns.DATA + " like ? )",
new String[]{"%" + bookpath + "%",
"%" + Constant.SUFFIX_TXT,
"%" + Constant.SUFFIX_PDF,
"%" + Constant.SUFFIX_EPUB,
"%" + Constant.SUFFIX_CHM}, null);
if (cursor != null && cursor.moveToFirst()) {
int idindex = cursor.getColumnIndex(MediaStore.Files.FileColumns._ID);
int dataindex = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
int sizeindex = cursor.getColumnIndex(MediaStore.Files.FileColumns.SIZE);
List<Recommend.RecommendBooks> list = new ArrayList<>();
do {
String path = cursor.getString(dataindex);
int dot = path.lastIndexOf("/");
String name = path.substring(dot + 1);
if (name.lastIndexOf(".") > 0)
name = name.substring(0, name.lastIndexOf("."));
Recommend.RecommendBooks books = new Recommend.RecommendBooks();
books._id = name;
books.path = path;
books.title = name;
books.isFromSD = true;
books.lastChapter = FileUtils.formatFileSizeToString(cursor.getLong(sizeindex));
list.add(books);
} while (cursor.moveToNext());
cursor.close();
mAdapter.addAll(list);
} else {
mAdapter.clear();
}
}