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:com.sferadev.etic.tasks.DownloadTasksTask.java
boolean instanceExists(String instancePath) { boolean exists = true; // Get the provider URI of the instance String where = InstanceColumns.INSTANCE_FILE_PATH + "=?"; String[] whereArgs = { instancePath }; ContentResolver cr = Collect.getInstance().getContentResolver(); Cursor cInstanceProvider = cr.query(InstanceColumns.CONTENT_URI, null, where, whereArgs, null); if (cInstanceProvider.getCount() != 1) { Log.e("MainListActivity:completeTask", "Unique instance not found: count is:" + cInstanceProvider.getCount()); exists = false;//from www.j ava 2s .c om } cInstanceProvider.close(); return exists; }
From source file:myblog.richard.vewe.launcher3.LauncherApplication.java
public User latestUser() { User u = null;/*from w ww. jav a 2s . c o m*/ ContentResolver resolver = getContentResolver(); String selection = UsersContract.TableUsers.Column.NAME + "=" + UsersContract.TableUsers.CURRENT; try { Cursor cursor = resolver.query(UsersContract.TableUsers.CONTENT_URI, UsersContract.TableUsers.BASIC_COLUMNS, selection, null, null); if (cursor == null || cursor.getCount() != 1) { Log.e(tag, "failed to query current user"); return null; } cursor.moveToFirst(); u = new User(cursor); cursor.close(); if (LOGD) { Log.d(tag, "current User " + u); } } catch (Exception e) { } finally { return u; } }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ??// w w w . j ava2 s . c om * @param messageType ?MMS,SMS,Email * @param folderType * @param index ? * @return ? */ private JSONObject getMessage(String messageType, String folderType, int index) throws JSONException { //TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONObject message = new JSONObject(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = getContext().getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return message; } // ?? if (!cursor.moveToPosition(index)) { cursor.close(); return message; } //TODO:?SIM?? message = getMessageFromCursor(cursor); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return message; }
From source file:net.naonedbus.manager.impl.CommentaireManager.java
public List<Commentaire> getAll(final ContentResolver contentResolver, final String codeLigne, final String codeSens, final String codeArret) { final Uri.Builder builder = CommentaireProvider.CONTENT_URI.buildUpon(); if (codeLigne != null) { builder.appendPath(codeLigne);// www. j a va 2s .c o m if (codeSens != null) { builder.appendPath(codeSens); if (codeArret != null) { builder.appendPath(codeArret); } } } final Cursor c = contentResolver.query(builder.build(), null, null, null, null); return getFromCursor(c); }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ??//from ww w . java2 s . c o m * @param messageType ?MMS,SMS,Email * @param folderType * @return ? */ private JSONArray getAllMessages(String messageType, String folderType) throws JSONException { //TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONArray messages = new JSONArray(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = getContext().getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return messages; } if (!cursor.moveToFirst()) { cursor.close(); return messages; } do { //TODO:?SIM?? JSONObject message = getMessageFromCursor(cursor); messages.put(message); } while (cursor.moveToNext()); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return messages; }
From source file:com.akop.bach.fragment.xboxlive.GamesFragment.java
@Override public void onCreate(Bundle state) { super.onCreate(state); if (mAccount == null) { Bundle args = getArguments();/*ww w .ja v a2s. c om*/ ContentResolver cr = getActivity().getContentResolver(); mAccount = (XboxLiveAccount) args.getParcelable("account"); mTitleId = getFirstTitleId(cr.query(Games.CONTENT_URI, new String[] { Games._ID, }, Games.ACCOUNT_ID + "=" + mAccount.getId(), null, Games.DEFAULT_SORT_ORDER)); } if (state != null && state.containsKey("account")) { mAccount = (XboxLiveAccount) state.getParcelable("account"); mTitleId = state.getLong("titleId"); } setHasOptionsMenu(true); }
From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java
private void synchronizeLocal() { getLoaderManager().restartLoader(0, null, mLoaderCallbacks); if (mTitleId >= 0) { boolean exists = false; boolean isDirty = false; ContentResolver cr = getActivity().getContentResolver(); Cursor cursor = cr.query(Games.CONTENT_URI, new String[] { Games.TITLE, Games.TROPHIES_DIRTY }, Games._ID + "=" + mTitleId, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { isDirty = (cursor.getInt(1) != 0); exists = true;// ww w. j a va 2s .c o m mGameTitle = cursor.getString(0); } } finally { cursor.close(); } } if (isDirty) synchronizeWithServer(); if (!exists) mTitleId = -1; } loadGameDetails(); }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ??//from w w w. j a va 2 s. c om * * @param messageType * ?MMS,SMS,Email * @param folderType * * @param index * ? * @return ? */ private JSONObject getMessage(String messageType, String folderType, int index) throws JSONException { // TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONObject message = new JSONObject(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return message; } // ?? if (!cursor.moveToPosition(index)) { cursor.close(); return message; } // TODO:?SIM?? message = getMessageFromCursor(cursor); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return message; }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ??//from w ww . j a v a 2 s .c o m * * @param messageType * ?MMS,SMS,Email * @param folderType * * @return ? */ private JSONArray getAllMessages(String messageType, String folderType) throws JSONException { // TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } JSONArray messages = new JSONArray(); try { // ??? String[] projection = new String[] { "_id", "subject", "address", "body", "date", "read" }; folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(uri, projection, null, null, "date desc"); if (null == cursor) { return messages; } if (!cursor.moveToFirst()) { cursor.close(); return messages; } do { // TODO:?SIM?? JSONObject message = getMessageFromCursor(cursor); messages.put(message); } while (cursor.moveToNext()); cursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); } return messages; }
From source file:myblog.richard.vewe.launcher3.LauncherApplication.java
private void loadFromContentProvider() { //get current user ContentResolver resolver = getContentResolver(); String selection = UsersContract.TableUsers.Column.NAME + "=" + UsersContract.TableUsers.CURRENT; try {//from w w w . j ava 2 s . c o m Cursor cursor = resolver.query(UsersContract.TableUsers.CONTENT_URI, UsersContract.TableUsers.BASIC_COLUMNS, selection, null, null); if (cursor == null || cursor.getCount() != 1) { Log.e(tag, "failed to query current user"); return; } cursor.moveToFirst(); mUser = new User(cursor); cursor.close(); if (LOGD) { Log.d(tag, "current User " + mUser); } mApplist.clear(); cursor = resolver.query(UsersContract.TableApplist.DIGA_URI, UsersContract.TableApplist.BASIC_COLUMNS, null, null, null); if (cursor == null) { Log.e(tag, "could not query all from table applist diga"); } else if (cursor.getCount() < 1) { if (LOGD) { Log.d(tag, "no entries in table applist diga"); } } else { while (cursor.moveToNext()) { App app = new App(cursor); if (LOGD) { Log.d(tag, "app: " + app); } mApplist.add(app); } cursor.close(); } } catch (Exception e) { Log.e(tag, "exception to query current user or applist"); } }