List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public static HttpHost checkAndroidProxy(Context context) { HttpHost proxy = null;/*w w w . j a va 2s.c om*/ if (!wifiEnable(context)) {// ??APN Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null && mCursor.moveToFirst()) { String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); int proxyPort = mCursor.getInt(mCursor.getColumnIndex("port")); if (proxyStr != null && proxyStr.trim().length() > 0) { if (0 == proxyPort) { proxyPort = 80; } proxy = new HttpHost(proxyStr, proxyPort); } mCursor.close(); } } return proxy; }
From source file:com.adjust.sdk.Util.java
protected static String getAttributionId(final Context context) { try {//from w ww . j a v a 2s . c o m final ContentResolver contentResolver = context.getContentResolver(); final Uri uri = Uri.parse("content://com.facebook.katana.provider.AttributionIdProvider"); final String columnName = "aid"; final String[] projection = { columnName }; final Cursor cursor = contentResolver.query(uri, projection, null, null, null); if (null == cursor) { return null; } if (!cursor.moveToFirst()) { cursor.close(); return null; } final String attributionId = cursor.getString(cursor.getColumnIndex(columnName)); cursor.close(); return attributionId; } catch (Exception e) { return null; } }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static String getNameFromEmail(Context context, String email) { if (context == null) { return null; }//from w w w. j a v a2 s. c o m if (loadContacts(context)) { try { String name = MainApplication.contacts.getJSONObject(email).getString("name"); Log.e(TAG, "getNameFromEmail - Email: " + email + ", Name: " + name); return name; } catch (JSONException e) { Log.e(TAG, "getNameFromEmail - failed: " + email); } } Log.e(TAG, "getNameFromEmail - Name queried: " + email); Cursor emailCursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.DATA + "='" + email + "'", null, null); if (emailCursor == null) { return "???"; } if (emailCursor.moveToNext()) { String name = emailCursor.getString( emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DISPLAY_NAME_PRIMARY)); Log.e(TAG, "getNameFromEmail - Email: " + email + ", Name: " + name); emailCursor.close(); return name; } emailCursor.close(); return email; }
From source file:im.delight.android.commons.Social.java
/** * Returns a list of phone numbers for the contact with the given lookup ID * * @param contactLookupId a contact's lookup ID to get the phone numbers for * @param context a context reference/*from w w w . j av a 2 s. c o m*/ * @return CharSequence[] a list of all phone numbers for the given contact or `null` */ public static CharSequence[] getContactPhone(final String contactLookupId, final Context context) { final Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; final String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }; final String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?"; final String[] selectionArgs = new String[] { contactLookupId }; final String sortOrder = null; Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder); String phone; if (result != null) { if (result.getCount() > 0) { final CharSequence[] res = new CharSequence[result.getCount()]; int i = 0; while (result.moveToNext()) { phone = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); if (phone != null) { res[i] = phone; i++; } } result.close(); return res; } else { result.close(); return null; } } else { return null; } }
From source file:im.delight.android.commons.Social.java
/** * Returns a list of email addresses for the contact with the given lookup ID * * @param contactLookupId a contact's lookup ID to get the email addresses for * @param context a context reference// www. j a va 2s . c o m * @return CharSequence[] a list of all email addresses for the given contact or `null` */ public static CharSequence[] getContactEmail(final String contactLookupId, final Context context) { final Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI; final String[] projection = new String[] { ContactsContract.CommonDataKinds.Email.DATA }; final String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?"; final String[] selectionArgs = new String[] { contactLookupId }; final String sortOrder = null; Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder); String email; if (result != null) { if (result.getCount() > 0) { final CharSequence[] res = new CharSequence[result.getCount()]; int i = 0; while (result.moveToNext()) { email = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); if (email != null) { res[i] = email; i++; } } result.close(); return res; } else { result.close(); return null; } } else { return null; } }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static Bitmap getPhotoFromEmail(Context context, String email) { if (context == null || email == null) { return null; }/*from w w w. j a v a 2 s . c o m*/ Bitmap result = MainApplication.avatarCache.get(email); if (result != null) { Log.e(TAG, "getPhotoFromEmail IN cache, Email: " + email); return result; } if (loadContacts(context)) { try { Log.e(TAG, "getPhotoFromEmail - Email: " + email + ", id: " + MainApplication.contacts.getJSONObject(email).getLong("id")); result = openPhoto(context, MainApplication.contacts.getJSONObject(email).getLong("id")); } catch (JSONException e) { Log.e(TAG, "getPhotoFromEmail - failed: " + email); } } else { Log.e(TAG, "getPhotoFromEmail - id queried: " + email); Cursor emailCursor = context.getContentResolver().query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.DATA + "='" + email + "'", null, null); while (emailCursor != null && emailCursor.moveToNext()) { Long contactId = Long.valueOf(emailCursor .getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.CONTACT_ID))); result = openPhoto(context, contactId); } if (emailCursor != null) { emailCursor.close(); } } if (result == null) { String name = getNameFromEmail(context, email); result = Utils.getDefaultAvatarInitials(context, name); } MainApplication.avatarCache.put(email, result); return result; }
From source file:com.onesignal.NotificationOpenedProcessor.java
private static void addChildNotifications(JSONArray dataArray, String summaryGroup, SQLiteDatabase writableDb) { String[] retColumn = { NotificationTable.COLUMN_NAME_FULL_DATA }; String[] whereArgs = { summaryGroup }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0 AND " + NotificationTable.COLUMN_NAME_IS_SUMMARY + " = 0", whereArgs, null, null, null); if (cursor.getCount() > 1) { cursor.moveToFirst();/*from w w w .j ava2s . co m*/ do { try { String jsonStr = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); dataArray.put(new JSONObject(jsonStr)); } catch (Throwable t) { OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Could not parse JSON of sub notification in group: " + summaryGroup); } } while (cursor.moveToNext()); } cursor.close(); }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
public static Share cursorToShare(Cursor c, Shoppinglist sl) { String email = c.getString(c.getColumnIndex(EMAIL)); String acceptUrl = c.getString(c.getColumnIndex(ACCEPT_URL)); String access = c.getString(c.getColumnIndex(ACCESS)); Share s = new Share(email, access, acceptUrl); s.setShoppinglistId(sl.getId());/*from w ww . ja va2 s . c om*/ s.setName(c.getString(c.getColumnIndex(NAME))); s.setAccepted(0 < c.getInt(c.getColumnIndex(ACCEPTED))); s.setState(c.getInt(c.getColumnIndex(STATE))); return s; }
From source file:info.staticfree.android.units.UnitUsageDBHelper.java
/** * Increments the usage counter for the given unit. * @param unit name of the unit/*from w ww .j a va2s. c o m*/ * @param db the unit usage database */ public static void logUnitUsed(String unit, ContentResolver cr) { final String[] selectionArgs = { unit }; final Cursor c = cr.query(UsageEntry.CONTENT_URI, INCREMENT_QUERY_PROJECTION, UsageEntry._UNIT + "=?", selectionArgs, null); if (c.getCount() > 0) { c.moveToFirst(); final int useCount = c.getInt(c.getColumnIndex(UsageEntry._USE_COUNT)); final int id = c.getInt(c.getColumnIndex(UsageEntry._ID)); final ContentValues cv = new ContentValues(); cv.put(UsageEntry._USE_COUNT, useCount + 1); cr.update(ContentUris.withAppendedId(UsageEntry.CONTENT_URI, id), cv, null, null); } else { final ContentValues cv = new ContentValues(); cv.put(UsageEntry._UNIT, unit); cv.put(UsageEntry._USE_COUNT, 1); cv.put(UsageEntry._FACTOR_FPRINT, getFingerprint(unit)); cr.insert(UsageEntry.CONTENT_URI, cv); } c.close(); }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
public static Shoppinglist cursorToSl(Cursor c) { Shoppinglist sl = Shoppinglist.fromName(c.getString(c.getColumnIndex(NAME))); sl.setId(c.getString(c.getColumnIndex(ID))); sl.setErn(c.getString(c.getColumnIndex(ERN))); String mod = c.getString(c.getColumnIndex(MODIFIED)); sl.setModified(Utils.stringToDate(mod)); sl.setAccess(c.getString(c.getColumnIndex(ACCESS))); sl.setState(c.getInt(c.getColumnIndex(STATE))); sl.setPreviousId(c.getString(c.getColumnIndex(PREVIOUS_ID))); sl.setType(c.getString(c.getColumnIndex(TYPE))); String meta = c.getString(c.getColumnIndex(META)); try {/*from www .ja v a 2s .c o m*/ sl.setMeta(meta == null ? null : new JSONObject(meta)); } catch (JSONException e) { EtaLog.e(TAG, null, e); } sl.setUserId(c.getInt(c.getColumnIndex(USER))); return sl; }