Example usage for android.database Cursor close

List of usage examples for android.database Cursor close

Introduction

In this page you can find the example usage for android.database Cursor close.

Prototype

void close();

Source Link

Document

Closes the Cursor, releasing all of its resources and making it completely invalid.

Usage

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getBannedThreads(String group, Context context) {

    HashSet<String> bannedThreads = null;

    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT clean_subject FROM banned_threads WHERE subscribed_group_id=" + groupid
            + " AND bandisabled=0";

    Cursor c = dbread.rawQuery(q, null);
    if (c.getCount() > 0) {

        bannedThreads = new HashSet<String>(c.getCount());
        c.moveToFirst();/*from   ww w.j av  a2  s .  c o m*/

        int count = c.getCount();
        for (int i = 0; i < count; i++) {
            bannedThreads.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (bannedThreads == null)
        bannedThreads = new HashSet<String>(0);
    return bannedThreads;
}

From source file:io.vit.vitio.Managers.ConnectDatabase.java

public int getCoursesCount() {
    String countQuery = "SELECT  * FROM " + TABLE_COURSES;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);

    int count = cursor.getCount();

    cursor.close();
    db.close();/*from   w  ww.j  a v a 2 s .com*/

    return count;
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

public E findOne(String rawQuery, String... params) {
    if (StringUtils.isNotEmpty(rawQuery)) {
        Cursor cursor = db.rawQuery(rawQuery, params);
        if ((cursor != null) && (cursor.getCount() == 1)) {
            E entity = mapToEntities(cursor).get(0);
            cursor.close();
            return entity;
        }/* w w  w . j  a  v  a 2s  .c  o m*/
    }
    return null;
}

From source file:com.dongfang.dicos.sina.UtilSina.java

public static HttpClient getNewHttpClient(Context context) {
    try {/*from  w  w  w  .  j  av  a  2  s .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();

        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);

        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, UtilSina.SET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, UtilSina.SET_SOCKET_TIMEOUT);
        HttpClient client = new DefaultHttpClient(ccm, params);
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (!wifiManager.isWifiEnabled()) {
            // ??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:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static String getFileAbsolutePath(Uri uri, Context c) {
    String fileName = null;/*w w  w  .j  a  v a2s  .  c o m*/
    String scheme = uri.getScheme();
    if (scheme.equals("file")) {
        fileName = uri.getPath();
    } else if (scheme.equals("content")) {
        Cursor cursor = null;
        try {
            String[] proj = { MediaStore.Images.Media.DATA };
            cursor = c.getContentResolver().query(uri, proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } catch (Exception e) {
            Log.e(LOG_NAME, "Error reading content URI", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    return fileName;
}

From source file:com.android.providers.downloads.DownloadInfo.java

/**
 * Query and return status of requested download.
 */// w w  w .j  av  a 2  s  . c  o  m
public static int queryDownloadStatus(ContentResolver resolver, long id) {
    final Cursor cursor = resolver.query(
            ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id),
            new String[] { Downloads.Impl.COLUMN_STATUS }, null, null, null);
    try {
        if (cursor.moveToFirst()) {
            return cursor.getInt(0);
        } else {
            // TODO: increase strictness of value returned for unknown
            // downloads; this is safe default for now.
            return Downloads.Impl.STATUS_PENDING;
        }
    } finally {
        cursor.close();
    }
}

From source file:com.googlecode.android_scripting.facade.SmsFacade.java

@Rpc(description = "Returns the number of messages.")
public Integer smsGetMessageCount(@RpcParameter(name = "unreadOnly") Boolean unreadOnly,
        @RpcParameter(name = "folder") @RpcDefault("inbox") String folder) {
    Uri uri = buildFolderUri(folder);/*from   w ww. j a v a 2 s .  co m*/
    Integer result = 0;
    String selection = buildSelectionClause(unreadOnly);
    Cursor cursor = mContentResolver.query(uri, null, selection, null, null);
    if (cursor != null) {
        result = cursor.getCount();
        cursor.close();
    } else {
        result = 0;
    }
    return result;
}

From source file:com.zzl.zl_app.cache.Utility.java

public static HttpClient getNewHttpClient(Context context) {
    try {//from w w w  .j  a v a2 s .co 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, Utility.SET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, 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:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static String[] getSubscribedGroups(Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor cur = dbread.rawQuery("SELECT name FROM subscribed_groups", null);
    int c = cur.getCount();
    String[] subscribed = null;/*  w  ww.  j av  a 2  s . co  m*/
    if (c > 0) {
        subscribed = new String[c];

        cur.moveToFirst();
        for (int i = 0; i < c; i++) {
            subscribed[i] = cur.getString(0);
            cur.moveToNext();
        }
    }

    cur.close();
    dbread.close();
    db.close();
    return subscribed;
}

From source file:org.francho.apps.zgzpolen.service.PollenService.java

/**
  * is the database udpdated?/* ww  w  .j a v a 2s  . c  o  m*/
  * 
  * @return
  */
private boolean isUpdated() {
    Cursor c = getContentResolver().query(Pollen.getPollenUri(), null, null, null, null);
    try {
        if (c.getCount() < 1) {
            return false;
        }
    } finally {
        c.close();
    }

    final SharedPreferences prefs = getSharedPreferences(POLLEN_SERVICE_PREFS, Context.MODE_PRIVATE);
    long lastTimeStamp = prefs.getLong(PREF_POLLEN_DATE, 0);

    Log.d(TAG, "" + System.currentTimeMillis() + " " + lastTimeStamp + ":"
            + (System.currentTimeMillis() - lastTimeStamp));

    return DateUtils.isToday(lastTimeStamp);
}