List of usage examples for android.database Cursor close
void close();
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static boolean isCached(String resourcePath) { String[] projection = new String[] { Nodes.NODE_IS_CACHED }; String selection = Nodes.NODE_RESOURCE_PATH + "=?"; String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {//w w w . j a va 2 s . co m if (c.moveToFirst()) { return c.getInt(c.getColumnIndex(Nodes.NODE_IS_CACHED)) != 0; } } finally { c.close(); } } return false; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static long getVolumeGeneration(String resourcePath) { String[] projection = new String[] { Volumes.VOLUME_GENERATION }; String selection = Volumes.VOLUME_RESOURCE_PATH + "=?"; String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Volumes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {/*from w w w .j av a 2 s . c o m*/ if (c.moveToFirst()) { return c.getLong(c.getColumnIndex(Volumes.VOLUME_GENERATION)); } } finally { c.close(); } } return 0; }
From source file:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.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 {/*from w ww . java 2 s . co 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:org.zywx.wbpalmstar.engine.EUtil.java
public static HttpHost checkAndroidProxy(Context context) { HttpHost proxy = null;//from www . j av a2s . c o m 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.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
static List<TaskList> loadNewListsFromDB(final Context context, final GoogleTaskList remoteList) { final Cursor c = context.getContentResolver().query(TaskList.URI, TaskList.Columns.FIELDS, GoogleTaskList.getTaskListWithoutRemoteClause(), remoteList.getTaskListWithoutRemoteArgs(), null); final ArrayList<TaskList> lists = new ArrayList<TaskList>(); try {//w w w . ja v a 2 s . c om while (c.moveToNext()) { lists.add(new TaskList(c)); } } finally { if (c != null) c.close(); } return lists; }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
/** * Get a HttpClient object which is setting correctly . * //w w w . j ava2s .com * @param context * : context of activity * @return HttpClient: HttpClient object */ public static HttpClient 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, Http_Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParameters, Http_Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(httpParameters); 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; }
From source file:Main.java
public static String checkNull(Context context, int lastImageId, File fileCapture) { final String[] imageColumns = { Images.Media._ID, Images.Media.DATA }; final String imageOrderBy = Images.Media._ID + " DESC"; final String imageWhere = Images.Media._ID + ">?"; final String[] imageArguments = { Integer.toString(lastImageId) }; ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy); if (cursor == null) return null; String newpath = null;//from www . j a v a 2 s .c o m if (cursor.getCount() >= 2) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID)); String data = cursor.getString(cursor.getColumnIndex(Images.Media.DATA)); if (data.equals(fileCapture.getPath())) { int rows = contentResolver.delete(Images.Media.EXTERNAL_CONTENT_URI, Images.Media._ID + "=?", new String[] { Long.toString(id) }); boolean ok = fileCapture.delete(); } else { newpath = data; } } } else { newpath = fileCapture.getPath(); Log.e("MediaUtils", "Not found duplicate."); } cursor.close(); return newpath; }
From source file:Main.java
/** * Convert image uri to file/*from www.j a v a2 s. c o m*/ */ public static String/*File*/ convertImageUriToFile(Context context, Uri imageUri) { Cursor cursor = null; try { String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID /*, MediaStore.Images.ImageColumns.ORIENTATION*/ }; cursor = context.getContentResolver().query(imageUri, projection, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int file_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); //int orientation_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION); if (cursor.moveToFirst()) { //String orientation = cursor.getString(orientation_ColumnIndex); return cursor.getString(file_ColumnIndex)/*new File(cursor.getString(file_ColumnIndex))*/; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static boolean isAuthorFavorite(String author, Context context) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbread = dbhelper.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id FROM favorite_users WHERE name=" + esc(author), null); boolean res = (c.getCount() > 0); c.close(); dbread.close();/* ww w. jav a2 s.com*/ dbhelper.close(); return res; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static boolean isGroupSubscribed(String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbread = dbhelper.getReadableDatabase(); Cursor cur = dbread.rawQuery("SELECT _id FROM subscribed_groups WHERE _id=" + groupid, null); boolean ret = (cur.getCount() > 0); cur.close(); dbread.close();/*w w w . jav a2 s .c o m*/ dbhelper.close(); return ret; }