List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ?message?//from ww w. j ava 2s . c o m */ private JSONObject getMessageFromCursor(Cursor cursor) throws JSONException { //?? String msgId = cursor.getString(cursor.getColumnIndex("_id")); String subject = cursor.getString(cursor.getColumnIndex("subject")); String smsBody = cursor.getString(cursor.getColumnIndex("body")); long date = cursor.getLong(cursor.getColumnIndex("date")); boolean isRead = cursor.getInt(cursor.getColumnIndex("read")) == 0 ? false : true; String destAddress = cursor.getString(cursor.getColumnIndex("address")); JSONObject message = new JSONObject(); message.put("messageId", msgId); message.put("subject", subject); message.put("body", smsBody); message.put("destinationAddresses", destAddress); message.put("messageType", MESSAGE_TYPE_SMS); message.put("date", date); message.put("isRead", isRead); return message; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ????/* w ww . ja v a2 s. c om*/ * * @return */ public static int qureyIMCountForSession(long threadId) { int count = 0; String[] columnsList = { "count(*)" }; String where = IMessageColumn.OWN_THREAD_ID + " = " + threadId + " and " + IMessageColumn.BOX_TYPE + " != 3"; Cursor cursor = null; try { cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_MESSAGE, columnsList, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getInt(cursor.getColumnIndex("count(*)")); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); cursor = null; } } return count; }
From source file:com.zsxj.pda.ui.client.LoginActivity.java
private boolean downloading() { DownloadManager.Query query = new DownloadManager.Query(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long downloadId = prefs.getLong(PrefKeys.DOWNLOAD_ID, 0); query.setFilterById(downloadId);/*from ww w . j a v a 2s .c o m*/ DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToNext()) { int statusIdx = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(statusIdx); if (DownloadManager.STATUS_RUNNING == status) { return true; } } return false; }
From source file:com.girnarsoft.android.shunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from ww w . j av a 2 s . c o m * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "=?", new String[] { locationSetting }, null); long location = 0; if (cursor.getCount() > 0) { cursor.moveToFirst(); location = cursor.getLong(cursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); location = ContentUris.parseId(uri); } return location; }
From source file:com.concentricsky.android.khanacademy.data.KADataService.java
private void updateDownloadStatus(Intent intent, final PendingIntent pendingIntent, final int startId) { final long id = intent.getLongExtra(EXTRA_ID, -1); final DownloadManager mgr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); final DownloadManager.Query q = new DownloadManager.Query(); q.setFilterById(id);/*from w w w . j a v a 2s . c om*/ new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... arg) { Cursor cursor = mgr.query(q); String youtubeId = null; int status = -1; if (cursor.moveToFirst()) { String filename = cursor .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME)); youtubeId = OfflineVideoManager.youtubeIdFromFilename(filename); status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); } cursor.close(); if (status == DownloadManager.STATUS_SUCCESSFUL && youtubeId != null) { try { Dao<Video, String> videoDao = helper.getVideoDao(); UpdateBuilder<Video, String> q = videoDao.updateBuilder(); q.where().eq("youtube_id", youtubeId); q.updateColumnValue("download_status", Video.DL_STATUS_COMPLETE); q.update(); return true; } catch (SQLException e) { e.printStackTrace(); } } return false; } @Override protected void onPostExecute(Boolean successful) { if (successful) { broadcastOfflineVideoSetChanged(); finish(startId, pendingIntent, RESULT_SUCCESS); } else { finish(startId, pendingIntent, RESULT_ERROR); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.msrproduction.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/* w ww. ja va2 s. c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToNext()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static String qureyVideoMsgLength(String msgId) { String count = null;/*from w w w. j a va2 s. c o m*/ String where = IMessageColumn.MESSAGE_ID + " = '" + msgId + "' "; Cursor cursor = null; try { cursor = getInstance().sqliteDB().rawQuery("select * from im_message where msgid=?", new String[] { String.valueOf(msgId) }); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getString(cursor.getColumnIndex(IMessageColumn.BODY)); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); cursor = null; } } return count; }
From source file:emroxriprap.com.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from www. ja v a 2 s .c om*/ * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; //check to see if this location already exists Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:ceruleanotter.github.com.sunshine.FetchWeatherTask.java
private long insertLocationInDatabase(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else {/*from w ww.j a v a 2 s . co m*/ Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
/****************************************************************************************** * Puts the data from a trip in database into vector ****************************************************************************************** * @param tripId Unique ID of each trip/*from w ww . ja v a 2 s. com*/ * @return Vector of the trip ******************************************************************************************/ private Vector<String> getTripData(long tripId) { Vector<String> tripData = new Vector<String>(); mDb.openReadOnly(); Cursor tripCursor = mDb.fetchTrip(tripId); setKcalCo2Savings(tripCursor); String note = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_NOTE)); String purpose = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_PURP)); Double startTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_START)); Double endTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_END)); tripCursor.close(); mDb.close(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); tripData.add(note); tripData.add(purpose); tripData.add(df.format(startTime)); tripData.add(df.format(endTime)); return tripData; }