List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:Main.java
public static long[] getAllSongs(Context context) { Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.IS_MUSIC + "=1", null, null); try {/*w w w .j av a 2 s . c om*/ if (c == null || c.getCount() == 0) { return null; } int len = c.getCount(); long[] list = new long[len]; for (int i = 0; i < len; i++) { c.moveToNext(); list[i] = c.getLong(0); } return list; } finally { if (c != null) { c.close(); } } }
From source file:Main.java
public static String getRecentCallsInfo(Context context) { StringBuilder stringBuilder = new StringBuilder(); Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, null, null, null, Calls.DATE + " DESC"); int number = cursor.getColumnIndex(Calls.NUMBER); int name = cursor.getColumnIndex(Calls.CACHED_NAME); int type = cursor.getColumnIndex(Calls.TYPE); int date = cursor.getColumnIndex(Calls.DATE); int duration = cursor.getColumnIndex(Calls.DURATION); while (cursor.moveToNext()) { String phNumber = cursor.getString(number); String cachedName = cursor.getString(name); String callType = cursor.getString(type); String callDuration = cursor.getString(duration); String callDate = cursor.getString(date); Date callDayTime = new Date(Long.valueOf(callDate)); String dir;/*from w w w . j a v a 2 s.co m*/ int dircode = Integer.parseInt(callType); switch (dircode) { case Calls.OUTGOING_TYPE: dir = "OUTGOING"; break; case Calls.INCOMING_TYPE: dir = "INCOMING"; break; case Calls.MISSED_TYPE: dir = "MISSED"; break; default: dir = "UNKNOWN " + dircode; } stringBuilder.append("\nPhone Number:--- ").append(phNumber).append("\nPhone formatted:--- ") .append(PhoneNumberUtils.formatNumber(phNumber)).append("\nCached name:--- ").append(cachedName) .append("\nCall Type:--- ").append(dir).append("\nCall Date:--- ").append(callDayTime) .append("\nCall duration in sec :--- ").append(callDuration) .append("\n----------------------------------"); } cursor.close(); return stringBuilder.toString(); }
From source file:Main.java
public static Uri getSMSLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { String[] smsLogArray = new String[2]; Uri uri = Uri.parse("content://sms/inbox"); Cursor cur = cr.query(uri, null, null, null, null); //Cursor cur= cr.query(uri, smsLogArray, null ,null,null); FileOutputStream fOut = null; try {/*from w w w . j a v a 2s . c o m*/ fOut = context.openFileOutput("sms_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { smsLogArray[0] = cur.getString(cur.getColumnIndexOrThrow("address")).toString(); smsLogArray[1] = cur.getString(cur.getColumnIndexOrThrow("body")).toString(); writeToOutputStreamArray(smsLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * In support of deleting a message, find all attachments and delete associated attachment * files./*from w ww . jav a2 s . co m*/ * @param context * @param accountId the account for the message * @param messageId the message */ public static void deleteAllAttachmentFiles(Context context, long accountId, long messageId) { Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor c = context.getContentResolver().query(uri, Attachment.ID_PROJECTION, null, null, null); try { while (c.moveToNext()) { long attachmentId = c.getLong(Attachment.ID_PROJECTION_COLUMN); File attachmentFile = getAttachmentFilename(context, accountId, attachmentId); // Note, delete() throws no exceptions for basic FS errors (e.g. file not found) // it just returns false, which we ignore, and proceed to the next file. // This entire loop is best-effort only. attachmentFile.delete(); } } finally { c.close(); } }
From source file:Main.java
public static String[] getTrailers(Cursor data) { List<String> lista = new ArrayList<String>(); lista.add("Select Trailer"); data.moveToFirst();/*from w w w. j a va2s .c o m*/ if (!data.getString(COL_TRAILER_KEY).equalsIgnoreCase("No Trailer Available")) { //loop through cursor to get all trailers for (int i = 1; i < data.getCount() + 1; i++) { if (!lista.contains(data.getString(COL_TRAILER_KEY))) { lista.add(data.getString(COL_TRAILER_KEY)); data.moveToNext(); } else { data.moveToNext(); } } } String[] ltrailer; if (lista.size() < 1) { ltrailer = new String[1]; ltrailer[0] = "No Trailer Available"; } else { ltrailer = lista.toArray(new String[lista.size()]); } return ltrailer; }
From source file:com.dahl.brendan.wordsearch.view.IOService.java
private static void writeFile(Context context, File file, boolean overwrite) { if (!file.exists() || overwrite) { Cursor cursor = context.getContentResolver().query(Word.CONTENT_URI, new String[] { Word.WORD }, null, null, null);/*from w w w .j a v a 2 s .co m*/ JSONArray array = new JSONArray(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { array.put(cursor.getString(0)); cursor.moveToNext(); } } try { file.getParentFile().mkdirs(); file.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(array.toString()); out.close(); } catch (IOException e) { Log.e(LOGTAG, "write failed", e); } } }
From source file:com.contentful.vault.SqliteHelper.java
static void deleteTables(SQLiteDatabase db) { String[] columns = new String[] { "name" }; String selection = "type = ? AND name != ?"; String[] args = new String[] { "table", "android_metadata" }; Cursor cursor = db.query("sqlite_master", columns, selection, args, null, null, null); List<String> tables = null; try {/*w ww . ja va 2 s . co m*/ if (cursor.moveToFirst()) { tables = new ArrayList<>(); do { tables.add(cursor.getString(0)); } while (cursor.moveToNext()); } } finally { cursor.close(); } if (tables != null) { db.beginTransaction(); try { for (String table : tables) { db.execSQL("DROP TABLE " + escape(table)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Returns the RawContact id for a sample SyncAdapter contact, or 0 if the * sample SyncAdapter user isn't found./* ww w . j ava 2s .com*/ * * @param context the Authenticator Activity context * @param userId the sample SyncAdapter user ID to lookup * @return the RawContact id, or 0 if not found */ private static List<Long> lookupAllContacts(ContentResolver resolver) { List<Long> result = new ArrayList<Long>(); final Cursor c = resolver.query(RawContacts.CONTENT_URI, AllUsersQuery.PROJECTION, AllUsersQuery.SELECTION, null, null); try { while (c.moveToNext()) { result.add(c.getLong(AllUsersQuery.COLUMN_ID)); } } finally { if (c != null) { c.close(); } } return result; }
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
public static List<MhSpRequest> listLatestRequests(Context context, String trollId, int count) { List<MhSpRequest> result = new ArrayList<MhSpRequest>(); String query = String.format(SQL_LIST_REQUESTS, count); MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getReadableDatabase(); Calendar calendar = Calendar.getInstance(); Cursor cursor = database.rawQuery(query, new String[] { trollId }); while (cursor.moveToNext()) { long startTimeMillis = cursor.getLong(0); long endTimeMillis = cursor.getLong(1); String scriptName = cursor.getString(2); String status = cursor.getString(3); calendar.setTimeInMillis(startTimeMillis); Date date = calendar.getTime(); PublicScript script = PublicScript.valueOf(scriptName); long duration = 0; if (endTimeMillis > 0) { duration = endTimeMillis - startTimeMillis; }//from w w w. j a va 2 s. com MhSpRequest request = new MhSpRequest(date, duration, script, status); result.add(request); } cursor.close(); database.close(); return result; }
From source file:Main.java
public static List<String> getAllNumbers(Activity callingActivity) { List<String> allNumbers = new ArrayList<String>(); Cursor managedCursor = callingActivity.managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null); int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER); int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE); int date = managedCursor.getColumnIndex(CallLog.Calls.DATE); int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION); StringBuilder sb = new StringBuilder(); sb.append("Call Details :"); while (managedCursor.moveToNext()) { String phNumber = managedCursor.getString(number); String callType = managedCursor.getString(type); String callDate = managedCursor.getString(date); Date callDayTime = new Date(Long.valueOf(callDate)); String callDuration = managedCursor.getString(duration); String dir = null;//from w w w. j a v a 2 s . co m if (!allNumbers.contains(phNumber)) { allNumbers.add(phNumber); } int dircode = Integer.parseInt(callType); switch (dircode) { case CallLog.Calls.OUTGOING_TYPE: dir = "OUTGOING"; break; case CallLog.Calls.INCOMING_TYPE: dir = "INCOMING"; break; case CallLog.Calls.MISSED_TYPE: dir = "MISSED"; break; } sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration); sb.append("\n----------------------------------"); // Log.i("getAllNumbers", sb.toString()); } managedCursor.close(); return allNumbers; }