List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static Map<Integer, List> getCityByPid(int id, File file) { String sql = "select cityid,city from city where provinceid= " + id; SQLiteDatabase db = null;/*from ww w . j a v a 2 s .c o m*/ Cursor c = null; Map<Integer, List> cityData = new HashMap<Integer, List>(); //List cityList = null; try { db = SQLiteDatabase.openOrCreateDatabase(file, null); c = db.rawQuery(sql, null); List cityList1 = new ArrayList(); List cityList2 = new ArrayList(); while (c.moveToNext()) { Map cityMap = new HashMap(); cityMap.put(c.getString(1), c.getInt(0)); cityList1.add(cityMap); cityList2.add(c.getString(1)); } cityData.put(0, cityList1); cityData.put(1, cityList2); } catch (Exception e) { Log.d("WineStock", "getCityByPid:" + e.getMessage()); } finally { if (c != null) { c.close(); } if (db != null) { db.close(); } } return cityData; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {/* w ww.j av a2 s . c o m*/ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:nz.co.wholemeal.christchurchmetro.Stop.java
private static ArrayList<Stop> doArrayListQuery(Context context, String query) { ArrayList<Stop> stops = new ArrayList<Stop>(); Log.d(TAG, "query: " + query); DatabaseHelper databaseHelper = new DatabaseHelper(context); SQLiteDatabase database = databaseHelper.getWritableDatabase(); Cursor cursor = database.rawQuery(query, null); try {//from w w w.j a v a 2 s.co m if (cursor.moveToFirst()) { do { Stop stop = new Stop(); stop.platformTag = cursor.getString(0); stop.platformNumber = cursor.getString(1); stop.name = cursor.getString(2); stop.roadName = cursor.getString(3); stop.latitude = cursor.getDouble(4); stop.longitude = cursor.getDouble(5); stops.add(stop); } while (cursor.moveToNext()); } } finally { cursor.close(); } Log.d(TAG, "stops.size() = " + stops.size()); database.close(); return stops; }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
public static String getAttributionId(ContentResolver contentResolver) { String[] projection = { ATTRIBUTION_ID_COLUMN_NAME }; Cursor c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null); if (c == null || !c.moveToFirst()) { return null; }/* w w w .ja v a 2s.c o m*/ String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); c.close(); return attributionId; }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
/** * Helper method that converts the cursor to a destination object. *///from www . j a v a 2 s . c o m static Destination getCursorDestination(Cursor mCursor) { Destination d = new Destination(); d.id = mCursor.getInt(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ID)); d.identifier = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_IDENTIFIER)); d.city = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_CITY)); d.region = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_REGION)); d.country = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_COUNTRY)); d.arrival = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ARRIVAL)); d.departure = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_DEPARTURE)); double lat = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LAT)); double lng = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LNG)); d.position = new LatLng(lat, lng); d.presentsDelivered = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTSDELIVERED)); d.presentsDeliveredAtDestination = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTS_DESTINATION)); d.timezone = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_TIMEZONE)); d.altitude = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ALTITUDE)); d.photoString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PHOTOS)); d.weatherString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_WEATHER)); d.streetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_STREETVIEW)); d.gmmStreetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_GMMSTREETVIEW)); // Process the panoramio string if possible d.photos = processPhoto(d.photoString); d.weather = processWeather(d.weatherString); d.streetView = processStreetView(d.streetViewString); d.gmmStreetView = processStreetView(d.gmmStreetViewString); return d; }
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 w w. ja v a 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:io.trigger.forge.android.modules.contprov.API.java
private static JSONArray extractNotesFromCursor(Cursor c) throws JSONException { JSONArray toRet = new JSONArray(); int[] cIndices = new int[] { c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_2_catname), c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_3_catstatus) }; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {//Extract note from cursor JSONObject o = new JSONObject(); o.put("name", c.getString(cIndices[0])); o.put("status", c.getString(cIndices[1])); //c.getString(cIndices[SERVER_ID]), toRet.put(o);// w w w . ja v a 2s . c om } return toRet; }
From source file:Main.java
public static Uri getAllContacts(ContentResolver cr, Uri internal, Context context, String timeStamp) { String[] contactsArray = new String[2]; Uri contactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; Cursor cur = cr.query(contactsUri, null, null, null, null); FileOutputStream fOut = null; try {//from ww w .j a v a 2 s . c om fOut = context.openFileOutput("contacts_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { contactsArray[0] = cur .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)) .toString(); contactsArray[1] = cur .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER)); writeToOutputStreamArray(contactsArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:Main.java
public static String getRealPathFromURI(Context context, long album_id) { Cursor cursor = null; try {/*from w ww . j ava 2 s. c o m*/ cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Albums.ALBUM_ART }, MediaStore.Audio.Albums._ID + "=?", new String[] { String.valueOf(album_id) }, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm"); String[] callLogArray = new String[3]; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor cur = cr.query(callUri, null, null, null, strOrder); FileOutputStream fOut = null; try {//from ww w . j ava 2s .co m fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME)); int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE); long seconds = cur.getLong(thirdIndex); String dateString = formatter.format(new Date(seconds)); callLogArray[2] = dateString; writeToOutputStreamArray(callLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }