List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:net.kourlas.voipms_sms.Database.java
/** * Gets all of the deleted messages in the database. * * @return All of the deleted messages in the database. *///ww w . java 2s . c om public synchronized Message[] getDeletedMessages(String did) { List<Message> messages = new ArrayList<>(); Cursor cursor = database.query(TABLE_MESSAGE, columns, COLUMN_DID + "=" + did + " AND " + COLUMN_DELETED + "=" + "1", null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { Message message = new Message(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATABASE_ID)), cursor.isNull(cursor.getColumnIndexOrThrow(COLUMN_VOIP_ID)) ? null : cursor.getLong(cursor.getColumnIndex(COLUMN_VOIP_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TYPE)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DID)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CONTACT)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_UNREAD)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELETED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERY_IN_PROGRESS))); messages.add(message); cursor.moveToNext(); } cursor.close(); Collections.sort(messages); Message[] messageArray = new Message[messages.size()]; return messages.toArray(messageArray); }
From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java
private void markFileTransferAsRead(Cursor cursor, String ftId) { try {/*w w w . j a v a 2 s . c o m*/ RcsService.Direction dir = RcsService.Direction .valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.DIRECTION))); if (RcsService.Direction.INCOMING == dir) { RcsService.ReadStatus status = RcsService.ReadStatus .valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.READ_STATUS))); if (RcsService.ReadStatus.UNREAD == status) { mFileTransferService.markFileTransferAsRead(ftId); if (LogUtils.isActive) { Log.d(LOGTAG, "Mark file transfer " + ftId + " as read"); } } } } catch (RcsServiceNotAvailableException e) { if (LogUtils.isActive) { Log.d(LOGTAG, "Cannot mark message as read: service not available"); } } catch (RcsGenericException | RcsPersistentStorageException e) { Log.e(LOGTAG, ExceptionUtil.getFullStackTrace(e)); } }
From source file:fr.cmoatoto.multishare.receiver.NanoHTTPDReceiver.java
public String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = mContext.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();//from ww w . j a v a2 s . co m String absolutePath = cursor.getString(column_index); if (cursor != null) cursor.close(); return absolutePath; }
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
private String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) { final String scheme = contentUri.getScheme(); if (scheme.compareTo("content") == 0) { String[] proj = { "_data" }; Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); cursor.moveToFirst();//from w w w . ja va 2 s . c o m return cursor.getString(column_index); } else if (scheme.compareTo("file") == 0) { return contentUri.getPath(); } else { return contentUri.toString(); } }
From source file:com.pheromone.plugins.FileUtils.java
/** * Allows the user to look up the Entry for a file or directory referred to by a local URI. * * @param url of the file/directory to look up * @return a JSONObject representing a Entry from the filesystem * @throws MalformedURLException if the url is not valid * @throws FileNotFoundException if the file does not exist * @throws IOException if the user can't read the file * @throws JSONException/* w ww . j a v a2 s .c o m*/ */ private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { String decoded = URLDecoder.decode(url, "UTF-8"); File fp = null; // Handle the special case where you get an Android content:// uri. if (decoded.startsWith("content:")) { Cursor cursor = this.ctx.managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null); // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data" int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); fp = new File(cursor.getString(column_index)); } else { // Test to see if this is a valid URL first @SuppressWarnings("unused") URL testUrl = new URL(decoded); if (decoded.startsWith("file://")) { fp = new File(decoded.substring(7, decoded.length())); } else { fp = new File(decoded); } } if (!fp.exists()) { throw new FileNotFoundException(); } if (!fp.canRead()) { throw new IOException(); } return getEntry(fp); }
From source file:net.kourlas.voipms_sms.Database.java
/** * Gets all of the messages associated with the specified contact phone number, except for deleted messages. * * @param contact The contact phone number. * @return All of the messages associated with the specified contact phone number, except for deleted messages. *//*from ww w.ja v a2 s.com*/ public synchronized Conversation getConversation(String did, String contact) { List<Message> messages = new ArrayList<>(); Cursor cursor = database.query(TABLE_MESSAGE, columns, COLUMN_CONTACT + "=" + contact + " AND " + COLUMN_DID + "=" + did + " AND " + COLUMN_DELETED + "=" + "0", null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { Message message = new Message(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATABASE_ID)), cursor.isNull(cursor.getColumnIndexOrThrow(COLUMN_VOIP_ID)) ? null : cursor.getLong(cursor.getColumnIndex(COLUMN_VOIP_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TYPE)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DID)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CONTACT)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_UNREAD)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELETED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERY_IN_PROGRESS))); messages.add(message); cursor.moveToNext(); } cursor.close(); Message[] messageArray = new Message[messages.size()]; messages.toArray(messageArray); return new Conversation(messageArray); }
From source file:com.android.providers.downloads.DownloadService.java
/** * Update {@link #mDownloads} to match {@link DownloadProvider} state. * Depending on current download state it may enqueue {@link DownloadThread} * instances, request {@link DownloadScanner} scans, update user-visible * notifications, and/or schedule future actions with {@link AlarmManager}. * <p>/*from w ww.j a v a2 s . c o m*/ * Should only be called from {@link #mUpdateThread} as after being * requested through {@link #enqueueUpdate()}. * * @return If there are active tasks being processed, as of the database * snapshot taken in this update. */ private boolean updateLocked() { final long now = mSystemFacade.currentTimeMillis(); boolean isActive = false; long nextActionMillis = Long.MAX_VALUE; final Set<Long> staleIds = Sets.newHashSet(mDownloads.keySet()); final ContentResolver resolver = getContentResolver(); Cursor cursor = null; try { cursor = resolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, null, null, null); final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver, cursor); final int idColumn = cursor.getColumnIndexOrThrow(Downloads.Impl._ID); while (cursor.moveToNext()) { final long id = cursor.getLong(idColumn); long currentDownloadNextActionMillis = Long.MAX_VALUE; DownloadInfo info = mDownloads.get(id); if (info != null) { updateDownload(reader, info, now); } else { // Check xunlei engine status when create a new task info = insertDownloadLocked(reader, now); } if (info.mDeleted) { // Delete download if requested, but only after cleaning up if (!TextUtils.isEmpty(info.mMediaProviderUri)) { resolver.delete(Uri.parse(info.mMediaProviderUri), null, null); } // if download has been completed, delete xxx, else delete xxx.midownload if (info.mStatus == Downloads.Impl.STATUS_SUCCESS) { if (info.mFileName != null) { deleteFileIfExists(info.mFileName); } } else { if (info.mFileName != null) { deleteFileIfExists(info.mFileName + Helpers.sDownloadingExtension); } } resolver.delete(info.getAllDownloadsUri(), null, null); } else { staleIds.remove(id); // Kick off download task if ready String pkg = TextUtils.isEmpty(info.mPackage) ? sUnknownPackage : info.mPackage; final boolean activeDownload = info.startDownloadIfReady(MyExecutor.getExecutorInstance(pkg)); // Kick off media scan if completed final boolean activeScan = info.startScanIfReady(mScanner); // get current download task's next action millis currentDownloadNextActionMillis = info.nextActionMillis(now); XLConfig.LOGD("Download " + info.mId + ": activeDownload=" + activeDownload + ", activeScan=" + activeScan); isActive |= activeDownload; isActive |= activeScan; // if equals 0, keep download service on. isActive |= (currentDownloadNextActionMillis == 0); } // Keep track of nearest next action nextActionMillis = Math.min(currentDownloadNextActionMillis, nextActionMillis); } } catch (SQLiteDiskIOException e) { XLConfig.LOGD("error when updateLocked: ", e); } catch (Exception e) { XLConfig.LOGD("error when updateLocked: ", e); } finally { if (cursor != null) { cursor.close(); } } // Clean up stale downloads that disappeared for (Long id : staleIds) { deleteDownloadLocked(id); } // Update notifications visible to user mNotifier.updateWith(mDownloads.values()); // Set alarm when next action is in future. It's okay if the service // continues to run in meantime, since it will kick off an update pass. if (nextActionMillis > 0 && nextActionMillis < Long.MAX_VALUE) { XLConfig.LOGD("scheduling start in " + nextActionMillis + "ms"); final Intent intent = new Intent(Constants.ACTION_RETRY); intent.setClass(this, DownloadReceiver.class); mAlarmManager.set(AlarmManager.RTC_WAKEUP, now + nextActionMillis, PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } return isActive; }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
/** * Allows the user to look up the Entry for a file or directory referred to by a local URI. * * @param url of the file/directory to look up * @return a JSONObject representing a Entry from the filesystem * @throws MalformedURLException if the url is not valid * @throws FileNotFoundException if the file does not exist * @throws IOException if the user can't read the file * @throws JSONException/* w w w .j ava2s . co m*/ */ @SuppressWarnings("deprecation") private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { String decoded = URLDecoder.decode(url, "UTF-8"); File fp = null; // Handle the special case where you get an Android content:// uri. if (decoded.startsWith("content:")) { Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null); // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data" int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); fp = new File(cursor.getString(column_index)); } else { // Test to see if this is a valid URL first @SuppressWarnings("unused") URL testUrl = new URL(decoded); if (decoded.startsWith("file://")) { int questionMark = decoded.indexOf("?"); if (questionMark < 0) { fp = new File(decoded.substring(7, decoded.length())); } else { fp = new File(decoded.substring(7, questionMark)); } } else { fp = new File(decoded); } } if (!fp.exists()) { throw new FileNotFoundException(); } if (!fp.canRead()) { throw new IOException(); } return getEntry(fp); }
From source file:com.android.leanlauncher.LauncherModel.java
/** Loads the workspace db */ private static Long loadWorkspaceDb(Context context) { final ContentResolver contentResolver = context.getContentResolver(); final Uri screensUri = LauncherSettings.Favorites.CONTENT_URI; final Cursor sc = contentResolver.query(screensUri, null, null, null, null); long screenId = 0; try {//from ww w . j a v a2 s . c om final int idIndex = sc.getColumnIndexOrThrow(LauncherSettings.Workspace._ID); while (sc.moveToNext()) { try { screenId = sc.getLong(idIndex); } catch (Exception e) { Log.d(TAG, "Desktop items loading interrupted - invalid screens: " + e); } } } finally { sc.close(); } return screenId; }
From source file:com.safecell.HomeScreenActivity.java
Bitmap getImageFromURI(Uri uri) { Bitmap resizedBitmap = null;//from www . j a v a 2 s .c o m String abc = null; if (uri != null) { String str = uri.toString(); abc = str.substring(0, 1); // Log.v("Safecell :" + "abc", str); } if (uri != null && abc.equalsIgnoreCase("c")) { Uri selectedImage = uri; // Log.v("Safecell :" + "Uri", selectedImage.toString()); String[] proj = { MediaColumns.DATA }; Cursor cursor = managedQuery(selectedImage, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); cursor.moveToFirst(); String path = cursor.getString(column_index); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; resizedBitmap = BitmapFactory.decodeFile(path, options); imageStoreInDatabase(resizedBitmap); cursor.close(); return resizedBitmap; } else if (uri != null && abc.equalsIgnoreCase("/")) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; resizedBitmap = BitmapFactory.decodeFile(uri.getPath(), options); imageStoreInDatabase(resizedBitmap); return resizedBitmap; } return resizedBitmap; }