Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

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

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:Main.java

public static ArrayList<String> getAllShownImagesPath(Activity activity) {
    Uri uri;//  w w  w  .ja  va 2 s .  co m
    Cursor cursor;
    int column_index_data, column_index_folder_name;
    ArrayList<String> listOfAllImages = new ArrayList<String>();
    String absolutePathOfImage = null;
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    String[] projection = { MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };

    cursor = activity.getContentResolver().query(uri, projection, null, null, null);

    column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
    column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
    while (cursor.moveToNext()) {
        absolutePathOfImage = cursor.getString(column_index_data);

        listOfAllImages.add(absolutePathOfImage);
    }
    return listOfAllImages;
}

From source file:com.karura.framework.plugins.Capture.java

/**
 * Queries the media store to find out what the file path is for the Uri we supply
 * /*from  ww  w  . java  2s.  c  o m*/
 * @param contentUri
 *            the Uri of the audio/image/video
 * @param context
 *            the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPathFromURI(Uri contentUri, Activity context) {
    final String scheme = contentUri.getScheme();

    if (scheme == null) {
        return contentUri.toString();
    } else if (scheme.compareTo("content") == 0) {
        String[] proj = { DATA };
        Cursor cursor = context.managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } else if (scheme.compareTo("file") == 0) {
        return contentUri.getPath();
    } else {
        return contentUri.toString();
    }
}

From source file:com.chess.genesis.data.GameDataDB.java

public static Bundle rowToBundle(final Cursor cursor, final int index, final boolean closeCursor) {
    final Bundle bundle = new Bundle();
    final String[] column = cursor.getColumnNames();

    cursor.moveToPosition(index);/* w  ww  . j  a  v  a 2  s  .c om*/
    for (int i = 0, len = cursor.getColumnCount(); i < len; i++)
        bundle.putString(column[i], cursor.getString(i));
    if (closeCursor)
        cursor.close();
    return bundle;
}

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  v  a2s.  c o m
    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:com.cyberocw.habittodosecretary.file.StorageHelper.java

public static String getRealPathFromURI(Context mContext, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = mContext.getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor == null) {
        return null;
    }//from  ww w  .j ava2 s . c om
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}

From source file:it.feio.android.omninotes.utils.StorageHelper.java

public static String getRealPathFromURI(Context mContext, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = mContext.getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor == null) {
        return null;
    }/*w  w w.j  av a  2  s .  c  o m*/
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static List<MhSpRequest> listLatestRequestsSince(Context context, String trollId, int dayCount) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.HOUR_OF_DAY, dayCount * -24);
    Date sinceDate = instance.getTime();

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(SQL_LIST_REQUESTS_SINCE,
            new String[] { trollId, "" + sinceDate.getTime() });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }/*from  w ww .  j  a va 2  s  . c  om*/
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

    cursor.close();
    database.close();

    return result;
}

From source file:com.zrlh.llkc.funciton.Http_Utility.java

/**
 * Get a HttpClient object which is setting correctly .
 * //from  ww w  .ja  va2 s.co  m
 * @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: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 {//w  w w  .jav  a2  s .  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;
}

From source file:com.ubuntuone.android.files.provider.MetaUtilities.java

public static boolean isDirectory(Cursor c) {
    final String type = c.getString(c.getColumnIndex(Nodes.NODE_KIND));
    return U1NodeKind.DIRECTORY == U1NodeKind.valueOf(type.toUpperCase(Locale.US));
}