List of usage examples for android.database Cursor close
void close();
From source file:com.csipsimple.backup.SipProfileJson.java
public static JSONArray serializeSipProfiles(Context ctxt) { JSONArray jsonSipProfiles = new JSONArray(); Cursor c = ctxt.getContentResolver().query(SipProfile.ACCOUNT_URI, DBProvider.ACCOUNT_FULL_PROJECTION, null, null, null);/*from w w w . j a v a 2s . c o m*/ if (c != null) { try { while (c.moveToNext()) { SipProfile account = new SipProfile(c); JSONObject p = serializeSipProfile(ctxt, account); try { jsonSipProfiles.put(jsonSipProfiles.length(), p); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add profile", e); } } } catch (Exception e) { Log.e(THIS_FILE, "Error on looping over sip profiles", e); } finally { c.close(); } } // Add negative fake accounts Map<String, String> callHandlers = CallHandlerPlugin.getAvailableCallHandlers(ctxt); for (String packageName : callHandlers.keySet()) { final Long externalAccountId = CallHandlerPlugin.getAccountIdForCallHandler(ctxt, packageName); SipProfile gsmProfile = new SipProfile(); gsmProfile.id = externalAccountId; JSONObject p = serializeSipProfile(ctxt, gsmProfile); try { jsonSipProfiles.put(jsonSipProfiles.length(), p); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add profile", e); } } return jsonSipProfiles; }
From source file:com.orm.androrm.migration.MigrationHelper.java
private void close(Cursor cursor) { cursor.close(); mAdapter.close(); }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
public static HttpClient getNewHttpClient(Context context) { try {//from w w w . ja va2s .c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Http_Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, Http_Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(ccm, params); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) { // ??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")); if (proxyStr != null && proxyStr.trim().length() > 0) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static List<RawContact> getLocalContacts(Context context, Uri uri) { Log.i(TAG, "*** Looking for local contacts"); List<RawContact> localContacts = new ArrayList<RawContact>(); final ContentResolver resolver = context.getContentResolver(); final Cursor c = resolver.query(uri, new String[] { Contacts._ID, RawContacts.SOURCE_ID }, null, null, null);//from ww w .j a v a 2 s . c o m try { while (c.moveToNext()) { final long rawContactId = c.getLong(0); final String serverContactId = c.getString(1); RawContact rawContact = RawContact.create(rawContactId, serverContactId); localContacts.add(rawContact); } } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... found " + localContacts.size()); return localContacts; }
From source file:busradar.madison.StopDialog.java
static RouteURL[] get_time_urls(int stopid) { Cursor c = G.db.rawQuery("SELECT url, route " + "FROM routestops " + "WHERE stopid = ? " + "ORDER BY route", new String[] { stopid + "" }); RouteURL[] list = new RouteURL[c.getCount()]; //ArrayList<RouteURL> list = new ArrayLst<RouteURL>(); //int last = -1; int i = 0;/* w w w .jav a2 s . c o m*/ while (c.moveToNext()) { RouteURL r = new RouteURL(); r.url = c.getString(0); r.route = c.getInt(1); list[i++] = r; } c.close(); return list; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static String getGroupNameFromId(int groupid, Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); String query = "SELECT name FROM subscribed_groups WHERE _id=" + groupid; Cursor cur = dbread.rawQuery(query, null); if (cur.getCount() != 1) { Log.w("GroundhogReader", "Trying to get name for groupid " + groupid + " which doesnt exists on DB"); cur.close(); dbread.close();// ww w .j av a2 s. com db.close(); return null; } cur.moveToFirst(); String groupname = cur.getString(0); cur.close(); dbread.close(); db.close(); return groupname; }
From source file:com.smarthome.deskclock.Alarms.java
/** * Disables non-repeating alarms that have passed. Called at * boot.// www . j a v a 2 s . co m */ public static void disableExpiredAlarms(final Context context) { Cursor cur = getFilteredAlarmsCursor(context.getContentResolver()); long now = System.currentTimeMillis(); if (cur.moveToFirst()) { do { Alarm alarm = new Alarm(cur); // A time of 0 means this alarm repeats. If the time is // non-zero, check if the time is before now. if (alarm.time != 0 && alarm.time < now) { Log.v("Disabling expired alarm set for " + Log.formatTime(alarm.time)); enableAlarmInternal(context, alarm, false); } } while (cur.moveToNext()); } cur.close(); }
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 www . j av a 2 s . c o 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.almarsoft.GroundhogReader.lib.DBUtils.java
public static int getGroupIdFromName(String group, Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); // First get the group ID String query = "SELECT _ID FROM subscribed_groups WHERE name=" + esc(group); Cursor cur = dbread.rawQuery(query, null); if (cur.getCount() != 1) { // WTF?? Log.w("GroundhogReader", "Trying to get id for group named " + group + " which doesnt exists on DB"); cur.close(); dbread.close();//from ww w . j a va 2 s .c om db.close(); return -1; } cur.moveToFirst(); int groupid = cur.getInt(0); cur.close(); dbread.close(); db.close(); return groupid; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
/** * For a given file {@link Uri} string, we check if its hash has a * corresponding entry in the {@link MetaProvider}, telling thus whether the * file from under given {@link Uri} string has been already uploaded. * /*from w w w . ja v a 2s . c o m*/ * @param uriString * the uri string which content we are checking * @return resourcePath if content under uri has been already uploaded, * null otherwise */ public static String isUploaded(String uriString) { File file = null; String fileHash = null; if (uriString.startsWith(ContentResolver.SCHEME_CONTENT)) { final String[] projection = new String[] { MediaColumns.DATA }; final Cursor c = sResolver.query(Uri.parse(uriString), projection, null, null, null); try { if (c.moveToFirst()) { String data = c.getString(c.getColumnIndex(MediaColumns.DATA)); file = new File(data); } else { return null; } } finally { c.close(); } } else if (uriString.startsWith(ContentResolver.SCHEME_FILE)) { final URI fileURI = URI.create(Uri.encode(uriString, ":/")); file = new File(fileURI); } else { Log.e(TAG, "Tried to check malformed uri string: " + uriString); return null; } try { if (file != null && file.exists()) { fileHash = HashUtils.getSha1(file); Log.d(TAG, String.format("Computed hash: '%s'", fileHash)); } else { throw new FileNotFoundException("isUploaded()"); } } catch (Exception e) { Log.e(TAG, "Can't compute file hash!", e); return null; } final String[] projection = new String[] { Nodes.NODE_RESOURCE_PATH }; final String selection = Nodes.NODE_HASH + "=?"; final String[] selectionArgs = new String[] { fileHash }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); String resourcePath = null; try { if (c.moveToFirst()) { resourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); Log.d(TAG, "Corresponding file hash found: " + resourcePath); } else { Log.d(TAG, "Corresponding file hash not found."); } } finally { c.close(); } return resourcePath; }