List of usage examples for android.content ContentResolver query
public final @Nullable Cursor query(@RequiresPermission.Read @NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder)
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSpeakersHandler.java
private static boolean isSpeakerUpdated(Uri uri, JSONObject speaker, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null); try {/*from w w w .j a v a2 s . c o m*/ if (!cursor.moveToFirst()) return false; final String curFirstName = cursor.getString(SpeakersQuery.FIRST_NAME).toLowerCase().trim(); final String curLastName = cursor.getString(SpeakersQuery.LAST_NAME).toLowerCase().trim(); final String curBio = cursor.getString(SpeakersQuery.BIO).toLowerCase().trim(); final String curCompany = cursor.getString(SpeakersQuery.COMPANY).toLowerCase().trim(); final String newFirstName = speaker.has("firstName") ? speaker.getString("firstName").toLowerCase().trim() : curFirstName; final String newLastName = speaker.has("lastName") ? speaker.getString("lastName").toLowerCase().trim() : curLastName; final String newBio = speaker.has("bio") ? speaker.getString("bio").toLowerCase().trim() : curBio; final String newCompany = speaker.has("company") ? speaker.getString("company").toLowerCase().trim() : curCompany; return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio) || !curCompany.equals(newCompany)); } finally { cursor.close(); } }
From source file:Main.java
public static void removeFromPlaylist(ContentResolver resolver, int audioId, long playlistId) { String[] cols = new String[] { "count(*)" }; Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); Cursor cur = resolver.query(uri, cols, null, null, null); cur.moveToFirst();//from w w w . j a v a 2s . c o m final int base = cur.getInt(0); cur.close(); ContentValues values = new ContentValues(); resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + audioId, null); }
From source file:Main.java
public static void addToMediaStorePlaylist(ContentResolver resolver, int audioId, long playlistId) { String[] cols = new String[] { "count(*)" }; Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); Cursor cur = resolver.query(uri, cols, null, null, null); cur.moveToFirst();//from w w w . ja v a 2 s.c o m final int base = cur.getInt(0); cur.close(); ContentValues values = new ContentValues(); values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId)); values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId); resolver.insert(uri, values); }
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); FileOutputStream fOut = null; try {//from www . j ava2 s .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:fr.mixit.android.io.JSONHandler.java
/** * Returns those id's from a {@link android.net.Uri} that were not found in a given set. *//* w w w . j a v a 2s .co m*/ protected static HashSet<String> getLostIds(Set<String> ids, Uri uri, String[] projection, int idColumnIndex, ContentResolver resolver) { final HashSet<String> lostIds = Sets.newHashSet(); final Cursor cursor = resolver.query(uri, projection, null, null, null); try { while (cursor.moveToNext()) { final String id = cursor.getString(idColumnIndex); if (!ids.contains(id)) { lostIds.add(id); } } } finally { cursor.close(); } if (!lostIds.isEmpty()) { Log.d(TAG, "Found " + lostIds.size() + " for " + uri.toString() + " that need to be removed."); } return lostIds; }
From source file:Main.java
public static Cursor getAllCallLogs(ContentResolver cr) { // reading all data in descending order according to DATE String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor curCallLogs = cr.query(callUri, null, null, null, strOrder); return curCallLogs; }
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 ww . ja v a2 s . 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.goliathonline.android.kegbot.io.RemoteKegHandler.java
private static ContentValues queryKegDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, KegsQuery.PROJECTION, null, null, null); try {//from w w w .java 2 s .co m if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(KegsQuery.UPDATED)); values.put(Kegs.KEG_STARRED, cursor.getInt(KegsQuery.STARRED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:fr.mixit.android.io.RemoteSpeakersHandler.java
private static boolean isSpeakerUpdated(Uri uri, JSONObject speaker, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null); try {//from w ww .j a v a2 s . c om if (!cursor.moveToFirst()) return false; final String curFirstName = cursor.getString(SpeakersQuery.FIRST_NAME).toLowerCase().trim(); final String curLastName = cursor.getString(SpeakersQuery.LAST_NAME).toLowerCase().trim(); final String curBio = cursor.getString(SpeakersQuery.BIO).toLowerCase().trim(); final String curCompany = cursor.getString(SpeakersQuery.COMPANY).toLowerCase().trim(); final String curLinkedIn = cursor.getString(SpeakersQuery.LINKEDIN).toLowerCase().trim(); final String curTwitter = cursor.getString(SpeakersQuery.TWITTER).toLowerCase().trim(); final String curBlog = cursor.getString(SpeakersQuery.BLOG).toLowerCase().trim(); final String newFirstName = speaker.has("firstName") ? speaker.getString("firstName").toLowerCase().trim() : curFirstName; final String newLastName = speaker.has("lastName") ? speaker.getString("lastName").toLowerCase().trim() : curLastName; final String newBio = speaker.has("bio") ? speaker.getString("bio").toLowerCase().trim() : curBio; final String newCompany = speaker.has("company") ? speaker.getString("company").toLowerCase().trim() : curCompany; final String newLinkedIn = speaker.has("linkedin") ? speaker.getString("linkedin").toLowerCase().trim() : curLinkedIn; final String newTwitter = speaker.has("twitter") ? speaker.getString("twitter").toLowerCase().trim() : curTwitter; final String newBlog = speaker.has("blog") ? speaker.getString("blog").toLowerCase().trim() : curBlog; return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio) || !curCompany.equals(newCompany) || !curLinkedIn.equals(newLinkedIn) || !curTwitter.equals(newTwitter) || !curBlog.equals(newBlog)); } finally { cursor.close(); } }
From source file:Main.java
public static ArrayList<String> getColumns(ContentResolver resolver, String uri, String[] projectionArray) { //String returnValue = ""; ArrayList<String> columns = new ArrayList<String>(); try {//from w ww. j a v a 2 s .co m //Issue query Cursor c = resolver.query(Uri.parse(uri), projectionArray, null, null, null); //Get all column names and display if (c != null) { String[] colNames = c.getColumnNames(); //Close the cursor c.close(); //String columnNamesOutput = ""; for (int k = 0; k < colNames.length; k++) columns.add(colNames[k]); } } catch (Throwable t) { } return columns; }