List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testCrashReport() throws Exception { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); // Log a test (fake) crash report. Checkin.reportCrash(r, new CrashData("Test", "Test Activity", new BuildData("Test Build", "123", start), new ThrowableData(new RuntimeException("Test Exception")))); // Crashes aren't indexed; go through them all to find the one we added. Cursor c = r.query(Checkin.Crashes.CONTENT_URI, null, null, null, null); Uri uri = null;/* w w w. j a v a 2 s .co m*/ while (c.moveToNext()) { String coded = c.getString(c.getColumnIndex(Checkin.Crashes.DATA)); byte[] bytes = Base64.decodeBase64(coded.getBytes()); CrashData crash = new CrashData(new DataInputStream(new ByteArrayInputStream(bytes))); // Should be exactly one recently added "Test" crash. if (crash.getId().equals("Test") && crash.getTime() > start) { assertEquals("Test Activity", crash.getActivity()); assertEquals("Test Build", crash.getBuildData().getFingerprint()); assertEquals("Test Exception", crash.getThrowableData().getMessage()); assertNull(uri); uri = ContentUris.withAppendedId(Checkin.Crashes.CONTENT_URI, c.getInt(c.getColumnIndex(Checkin.Crashes._ID))); } } assertNotNull(uri); c.close(); // Update the "logs" column. ContentValues values = new ContentValues(); values.put(Checkin.Crashes.LOGS, "Test Logs"); assertEquals(1, r.update(uri, values, null, null)); c = r.query(uri, null, null, null, null); assertTrue(c.moveToNext()); String logs = c.getString(c.getColumnIndex(Checkin.Crashes.LOGS)); assertEquals("Test Logs", logs); c.deleteRow(); c.close(); c.requery(); assertFalse(c.moveToNext()); c.close(); }
From source file:net.nordist.lloydproof.CorrectionStorage.java
public JSONArray getAllAsJSONArray() throws JSONException { openReadDB();/*from ww w . j a v a 2s. c om*/ Cursor cursor = readDB.query(TABLE_NAME, new String[] { "id", "current_text" }, null, null, null, null, null); JSONArray jarray = new JSONArray(); while (cursor.moveToNext()) { jarray.put(getNextAsJSONObject(cursor)); } return jarray; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static String[] getSubscribedGroups(Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor cur = dbread.rawQuery("SELECT name FROM subscribed_groups", null); int c = cur.getCount(); String[] subscribed = null;//from w ww . j a v a 2 s. c o m if (c > 0) { subscribed = new String[c]; cur.moveToFirst(); for (int i = 0; i < c; i++) { subscribed[i] = cur.getString(0); cur.moveToNext(); } } cur.close(); dbread.close(); db.close(); return subscribed; }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Returns a List of all message IDs.") public List<Integer> smsGetMessageIds(@RpcParameter(name = "unreadOnly") Boolean unreadOnly, @RpcParameter(name = "folder") @RpcDefault("inbox") String folder) { Uri uri = buildFolderUri(folder);/*from w ww . j a v a2s .co m*/ List<Integer> result = new ArrayList<Integer>(); String selection = buildSelectionClause(unreadOnly); String[] columns = { "_id" }; Cursor cursor = mContentResolver.query(uri, columns, selection, null, null); while (cursor != null && cursor.moveToNext()) { result.add(cursor.getInt(0)); } cursor.close(); return result; }
From source file:asu.edu.msse.gpeddabu.moviedescriptions.AddMovie.java
public void getGenreList() { genreArr = new ArrayList<>(); try {// w w w . j a v a2 s. c o m MovieDB db = new MovieDB(con); SQLiteDatabase crsDB = db.openDB(); Cursor cur = crsDB.rawQuery("select distinct genre from movie;", null); while (cur.moveToNext()) { genreArr.add(cur.getString(0)); } cur.close(); crsDB.close(); db.close(); } catch (Exception ex) { android.util.Log.w(this.getClass().getSimpleName(), "Exception getting genre info: " + ex.getMessage()); } }
From source file:org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase.java
@Override protected List<Cookie> loadCookies() { final List<Cookie> list = new LinkedList<Cookie>(); final Cursor cursor = myDatabase .rawQuery("SELECT cookie_id,host,path,name,value,date_of_expiration,secure FROM Cookie", null); while (cursor.moveToNext()) { final long id = cursor.getLong(0); final String host = cursor.getString(1); final String path = cursor.getString(2); final String name = cursor.getString(3); final String value = cursor.getString(4); final Date date = SQLiteUtil.getDate(cursor, 5); final boolean secure = cursor.getLong(6) == 1; Set<Integer> portSet = null; final Cursor portsCursor = myDatabase.rawQuery("SELECT port FROM CookiePort WHERE cookie_id = " + id, null);//from w w w. jav a2 s.c om while (portsCursor.moveToNext()) { if (portSet == null) { portSet = new HashSet<Integer>(); } portSet.add((int) portsCursor.getLong(1)); } portsCursor.close(); final BasicClientCookie2 c = new BasicClientCookie2(name, value); c.setDomain(host); c.setPath(path); if (portSet != null) { final int ports[] = new int[portSet.size()]; int index = 0; for (int p : portSet) { ports[index] = p; ++index; } c.setPorts(ports); } c.setExpiryDate(date); c.setSecure(secure); c.setDiscard(false); list.add(c); } cursor.close(); return list; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static HashSet<String> getFavoriteAuthors(Context context) { HashSet<String> favoriteAuthors = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT name FROM favorite_users", null); if (c.getCount() > 0) { favoriteAuthors = new HashSet<String>(c.getCount()); c.moveToFirst();/*from ww w. java 2s .co m*/ int count = c.getCount(); for (int i = 0; i < count; i++) { favoriteAuthors.add(c.getString(0)); c.moveToNext(); } } c.close(); dbread.close(); db.close(); if (favoriteAuthors == null) favoriteAuthors = new HashSet<String>(0); return favoriteAuthors; }
From source file:com.prey.json.actions.RecentCallsList.java
public HttpDataService run(Context ctx, List<ActionResult> lista, JSONObject parameters) { HttpDataService data = new HttpDataService("recent_calls_list"); HashMap<String, String> parametersMap = new HashMap<String, String>(); final String[] projection = null; final String selection = null; final String[] selectionArgs = null; final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null; try {/*w w w. jav a 2s.c o m*/ cursor = ctx.getContentResolver().query(Uri.parse("content://call_log/calls"), projection, selection, selectionArgs, sortOrder); int i = 0; while (cursor.moveToNext()) { // String callLogID = // cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls._ID)); String callNumber = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); String callDate = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String callType = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE)); // String isCallNew = // cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NEW)); String duration = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DURATION)); parametersMap.put(i + "][number", callNumber); parametersMap.put(i + "][date", callDate); parametersMap.put(i + "][type", callType); parametersMap.put(i + "][duration", duration); i++; } data.setList(true); data.addDataListAll(parametersMap); } catch (Exception ex) { ex.printStackTrace(); } finally { cursor.close(); } return data; }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Returns a List of all messages.", returns = "a List of messages as Maps") public List<JSONObject> smsGetMessages(@RpcParameter(name = "unreadOnly") Boolean unreadOnly, @RpcParameter(name = "folder") @RpcDefault("inbox") String folder, @RpcParameter(name = "attributes") @RpcOptional JSONArray attributes) throws JSONException { List<JSONObject> result = new ArrayList<JSONObject>(); Uri uri = buildFolderUri(folder);/*from w ww .ja va2 s.c om*/ String selection = buildSelectionClause(unreadOnly); String[] columns; if (attributes == null || attributes.length() == 0) { // In case no attributes are specified we set the default ones. columns = new String[] { "_id", "address", "date", "body", "read" }; } else { // Convert selected attributes list into usable string list. columns = new String[attributes.length()]; for (int i = 0; i < attributes.length(); i++) { columns[i] = attributes.getString(i); } } Cursor cursor = mContentResolver.query(uri, columns, selection, null, null); while (cursor != null && cursor.moveToNext()) { JSONObject message = new JSONObject(); for (int i = 0; i < columns.length; i++) { message.put(columns[i], cursor.getString(i)); } result.add(message); } cursor.close(); return result; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static Vector<Long> getPendingOutgoingMessageIds(Context context) { Vector<Long> retVal = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id FROM offline_sent_posts", null); int count = c.getCount(); if (count == 0) { retVal = new Vector<Long>(0); } else {//www.j av a2 s . c om retVal = new Vector<Long>(count); c.moveToFirst(); for (int i = 0; i < count; i++) { retVal.add(c.getLong(0)); c.moveToNext(); } } c.close(); dbread.close(); db.close(); return retVal; }