本文整理了Java中android.database.Cursor.close()
方法的一些代码示例,展示了Cursor.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.close()
方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:close
暂无
代码示例来源:origin: stackoverflow.com
Cursor cursor = db.rawQuery(...);
try {
while (cursor.moveToNext()) {
...
}
} finally {
cursor.close();
}
代码示例来源:origin: stackoverflow.com
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
代码示例来源:origin: stackoverflow.com
private String getNote(long contactId) {
String note = null;
String[] columns = new String[] { ContactsContract.CommonDataKinds.Note.NOTE };
String where = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters = new String[]{Long.toString(contactId), ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor contacts = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, where, whereParameters, null);
if (contacts.moveToFirst()) {
rv = contacts.getString(0);
}
contacts.close();
return note;
}
代码示例来源:origin: square/sqlbrite
@Override public String apply(Query query) {
Cursor cursor = query.run();
try {
if (!cursor.moveToNext()) {
throw new AssertionError("No rows");
}
return cursor.getString(0);
} finally {
cursor.close();
}
}
});
代码示例来源:origin: aa112901/remusic
public static Uri getAlbumUri(Context context, long musicId) {
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI, proj_music, "_id =" + String.valueOf(musicId), null, null);
long id = -3;
if (cursor == null) {
return null;
}
if (cursor.moveToFirst()) {
id = cursor.getInt(cursor.getColumnIndex(Media.ALBUM_ID));
}
cursor.close();
return getAlbumArtUri(id);
}
代码示例来源:origin: xinghongfei/LookLook
public boolean isRead(String table, String key, int value) {
boolean isRead = false;
Cursor cursor = mSQLiteDatabase.query(table, null, "key=?", new String[]{key}, null, null, null);
if (cursor.moveToNext() && (cursor.getInt(cursor.getColumnIndex("is_read")) == value)) {
isRead = true;
}
cursor.close();
return isRead;
}
代码示例来源:origin: stackoverflow.com
Cursor mCount= db.rawQuery("select count(*) from users where uname='" + loginname + "' and pwd='" + loginpass +"'", null);
mCount.moveToFirst();
int count= mCount.getInt(0);
mCount.close();
代码示例来源:origin: greenrobot/greenDAO
/** Returns the count (number of results matching the query). Uses SELECT COUNT (*) sematics. */
public long count() {
checkThread();
Cursor cursor = dao.getDatabase().rawQuery(sql, parameters);
try {
if (!cursor.moveToNext()) {
throw new DaoException("No result for count");
} else if (!cursor.isLast()) {
throw new DaoException("Unexpected row count: " + cursor.getCount());
} else if (cursor.getColumnCount() != 1) {
throw new DaoException("Unexpected column count: " + cursor.getColumnCount());
}
return cursor.getLong(0);
} finally {
cursor.close();
}
}
代码示例来源:origin: naman14/Timber
public static final SortedCursor makeRecentTracksCursor(final Context context) {
Cursor songs = RecentStore.getInstance(context).queryRecentIds(null);
try {
return makeSortedCursor(context, songs,
songs.getColumnIndex(SongPlayCount.SongPlayCountColumns.ID));
} finally {
if (songs != null) {
songs.close();
songs = null;
}
}
}
代码示例来源:origin: stackoverflow.com
public String getRealPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
if(cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
代码示例来源:origin: bumptech/glide
@Nullable
private String getPath(@NonNull Uri uri) {
final Cursor cursor = query.query(uri);
try {
if (cursor != null && cursor.moveToFirst()) {
return cursor.getString(0);
} else {
return null;
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
代码示例来源:origin: greenrobot/greenDAO
public static String queryString(Database db, String sql) {
Cursor cursor = db.rawQuery(sql, null);
try {
assertTrue(cursor.moveToNext());
return cursor.getString(0);
} finally {
cursor.close();
}
}
代码示例来源:origin: bumptech/glide
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CONTACT && resultCode == RESULT_OK) {
Uri uri = Preconditions.checkNotNull(data.getData());
final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
final long contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
showContact(contactId);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
@Override
public SourceInfo get(String url) {
checkNotNull(url);
Cursor cursor = null;
try {
cursor = getReadableDatabase().query(TABLE, ALL_COLUMNS, COLUMN_URL + "=?", new String[]{url}, null, null, null);
return cursor == null || !cursor.moveToFirst() ? null : convert(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
代码示例来源:origin: lingochamp/FileDownloader
@Override
public FileDownloadModel find(final int id) {
Cursor c = null;
try {
c = db.rawQuery(FileDownloadUtils.formatString("SELECT * FROM %s WHERE %s = ?",
TABLE_NAME, FileDownloadModel.ID), new String[]{Integer.toString(id)});
if (c.moveToNext()) return createFromCursor(c);
} finally {
if (c != null) c.close();
}
return null;
}
代码示例来源:origin: stackoverflow.com
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case REQ_CODE_PICK_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
}
}
}
代码示例来源:origin: naman14/Timber
public static Album getAlbum(Cursor cursor) {
Album album = new Album();
if (cursor != null) {
if (cursor.moveToFirst())
album = new Album(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getLong(3), cursor.getInt(4), cursor.getInt(5));
}
if (cursor != null)
cursor.close();
return album;
}
代码示例来源:origin: square/sqlbrite
public void isExhausted() {
if (cursor.moveToNext()) {
StringBuilder data = new StringBuilder();
for (int i = 0; i < cursor.getColumnCount(); i++) {
if (i > 0) data.append(", ");
data.append(cursor.getString(i));
}
throw new AssertionError("Expected no more rows but was: " + data);
}
cursor.close();
}
}
代码示例来源:origin: stackoverflow.com
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
long id = mgr.enqueue(request);
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(id);
Cursor cursor = mgr.query(q);
cursor.moveToFirst();
int bytes_downloaded = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
cursor.close();
代码示例来源:origin: greenrobot/greenDAO
public void testExecuteSqlScript() throws IOException {
DbUtils.executeSqlScript(getContext(), db, "minimal-entity.sql");
Cursor cursor = db.rawQuery("SELECT count(*) from MINIMAL_ENTITY", null);
try {
cursor.moveToFirst();
assertEquals(5, cursor.getInt(0));
} finally {
cursor.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!