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.phicomm.account.operator.GetMapOperation.java

@Override
public Bundle execute(Context context, Request request) {
    String ssession_id = null;/*from www .  j ava2 s .  c  om*/
    Bundle resultData = new Bundle();
    Cursor persionCursor = context.getContentResolver().query(Provider.PersonColumns.CONTENT_URI, null, null,
            null, null);
    if (persionCursor != null) {
        if (persionCursor.moveToFirst()) {
            ssession_id = persionCursor
                    .getString(persionCursor.getColumnIndex(Provider.PersonColumns.JSSESSIONID));
        }
        persionCursor.close();
    }

    String url = WSConfig.WS_GET_MAP_URL + ssession_id;
    NetworkConnection networkConnection1 = new NetworkConnection(context, url);
    ArrayList<BasicNameValuePair> parameterList = new ArrayList<BasicNameValuePair>();
    BasicNameValuePair value = new BasicNameValuePair("XML", "");
    parameterList.add(value);
    networkConnection1.setParameters(parameterList);
    try {
        ConnectionResult result = networkConnection1.execute();
        resultData.putString("result", result.body);
        Log.i("ss", "map________________________________result.body:" + result.body);
    } catch (ConnectionException e) {
        e.printStackTrace();
    }
    Log.i("ss", "_______________________________________OK");
    return resultData;
}

From source file:Main.java

/**
 * Try to get the exif orientation of the passed image uri
 * //ww  w.j  av  a 2s  . c om
 * @param context
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {

    final String scheme = uri.getScheme();

    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            return 0;
        }

        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri,
                        new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null,
                        null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }

            if (result == null) {
                return 0;
            }

            int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA);

            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();

                    int rotation = 0;

                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }

                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    return 0;
}

From source file:com.haoqee.chatsdk.net.Utility.java

/**
 * Get a HttpClient object which is setting correctly .
 * /*from   w  ww.  j a v a  2s.c  o  m*/
 * @param context
 *            : context of activity
 * @return HttpClient: HttpClient object
 */
public static DefaultHttpClient getHttpClient(Context context) {
    BasicHttpParams httpParameters = new BasicHttpParams();
    // Set the default socket timeout (SO_TIMEOUT) // in
    // milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT);
    DefaultHttpClient client = new DefaultHttpClient(httpParameters);
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        // ??PN????
        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;
}

From source file:it.ms.theing.loquitur.functions.Storage.java

/**
 * Get a key value//  w ww.  j  a  va2  s .  c o  m
 * @param genre
 * The genre of the key
 * @param key
 * The key
 * @return
 * The key value
 */
@JavascriptInterface
public String getKey(String genre, String key) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=? and key=?",
            new String[] { genre.toUpperCase(), key });
    cursor.moveToFirst();
    if (cursor.isAfterLast()) {
        return "";
    }
    String s = cursor.getString(2);
    cursor.close();
    return s;
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

/**
 * Returns the destination with the given _id.
 *///from  ww w .ja  va 2  s .  c  o  m
public Destination getDestination(int id) {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_NAME_ID + " = " + id, null);
    c.moveToFirst();
    Destination d = getCursorDestination(c);
    c.close();

    return d;
}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * @return the amount of chatrooms in the database.
 *//*w  w w .j a  v a 2s  .  c  o  m*/
public int getChatroomsCount() {
    String countQuery = "SELECT  * FROM " + TABLE_CHATROOMS;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    if (cursor != null) {
        cursor.moveToFirst();
    }
    int count = cursor.getCount();
    cursor.close();

    // return count
    return count;
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

public String getRealImagePathFromURI(Uri contentUri) {
    String res = null;//  ww  w. j  a v a 2s .co m
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor.moveToFirst()) {
        ;
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        res = cursor.getString(column_index);
    }
    cursor.close();
    return res;
}

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

public boolean itemExist(String name, String format) {
    String selection = SavedItemsTable.NAME + " =? AND " + SavedItemsTable.FILE_FORMAT + " =?";
    Cursor cursor = context.getContentResolver().query(MobileDbProvider.SAVED_ITEMS_CONTENT_URI,
            new String[] { SavedItemsTable._ID }, selection, new String[] { name, format }, null);
    boolean itemExist = cursor != null && cursor.getCount() != 0;
    if (cursor != null) {
        cursor.close();
    }/*  ww  w  .  j  av a2 s .  c  o m*/
    return itemExist;
}

From source file:Main.java

/**
 * Try to get the exif orientation of the passed image uri
 *
 * @param context/*from w  w w  .  j ava 2s  .co m*/
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {

    final String scheme = uri.getScheme();

    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            return 0;
        }

        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION,
                        MediaStore.Images.ImageColumns.DATA }, null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }

            if (result == null) {
                return 0;
            }

            int orientationColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.DATA);

            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();

                    int rotation = 0;

                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }

                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    return 0;
}

From source file:com.github.gw2app.events.Gw2ApiEvents.java

private List<Gw2Event> _getEvents(String url) {
    Log.d("Gw2", "Fetching event names from DB.");
    SQLiteDatabase db = this.dbhelper.getWritableDatabase();
    Cursor cursor = db.query(Gw2DB.EVENT_NAMES_TABLE, null, null, null, null, null, null);
    HashMap<String, String> eventNames = new HashMap<String, String>();

    if (cursor.getCount() == 0) {
        cursor.close();
        return new ArrayList<Gw2Event>();
    }/*from   w w  w  .  j ava  2  s . co m*/

    cursor.moveToFirst();
    while (!cursor.isLast()) {
        String id = cursor.getString(0);
        String name = cursor.getString(1);
        eventNames.put(id, name);
        cursor.moveToNext();
    }
    cursor.close();

    Log.d("Gw2", "Fetching event data from JSON");
    ArrayList<Gw2Event> list = new ArrayList<Gw2Event>();
    try {
        //Log.d("Gw2", url);
        String result = this.fetchJSONfromURL(url);
        JSONObject jsData = new JSONObject(result);
        JSONArray jsArray = jsData.getJSONArray("events");

        for (int i = 0; i < jsArray.length(); i++) {
            JSONObject obj = jsArray.getJSONObject(i);
            int world_id = obj.getInt("world_id");
            int map_id = obj.getInt("map_id");
            String event_id = obj.getString("event_id");
            String state = obj.getString("state");
            list.add(new Gw2Event(world_id, map_id, event_id, state, eventNames.get(event_id)));
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return list;
}