Example usage for android.database Cursor getColumnIndex

List of usage examples for android.database Cursor getColumnIndex

Introduction

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

Prototype

int getColumnIndex(String columnName);

Source Link

Document

Returns the zero-based index for the given column name, or -1 if the column doesn't exist.

Usage

From source file:de.escoand.readdaily.DownloadHandler.java

public static void stopDownload(final Context context, final String name) {
    Database db = Database.getInstance(context);
    Cursor c = db.getDownloads();
    long id = 0;//from   w ww  .j ava2s  .c o m

    // get download id
    while (c.moveToNext())
        if (c.getString(c.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) {
            id = c.getLong(c.getColumnIndex(Database.COLUMN_ID));
            break;
        }
    c.close();
    if (id <= 0)
        return;

    // stop download
    ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).remove(id);
    db.removeDownload(id);
}

From source file:Main.java

public static Cursor getAllCallLogAboutACaller(Context context, String callerNumber) {
    // cancello la chiamata in uscita se nelle preferenze ? settata tale opzione
    Uri delUri = Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, "");
    Cursor cursor = context.getContentResolver().query(delUri, null,
            android.provider.CallLog.Calls.NUMBER + "=?", new String[] { "404" }, null);
    try {//w ww  . j  av a2s  . c o  m
        boolean moveToFirst = cursor.moveToFirst();
        Log.i("MOVETOFIRST", "moveToFirst=" + moveToFirst);
        do {
            int numberColumn = cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
            String callerPhoneNumber = cursor.getString(numberColumn);
            Log.i(TAG, "numero : " + callerPhoneNumber);
        } while (cursor.moveToNext());

    } catch (Exception e) {
        Log.e(TAG, "Problem moving to first entry", e);
    }
    return cursor;
}

From source file:Main.java

public static File getFromMediaUri(ContentResolver resolver, Uri uri) {
    if (uri == null)
        return null;
    if ("file".equals(uri.getScheme())) {
        return new File(uri.getPath());
    } else if ("content".equals(uri.getScheme())) {
        final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME };
        Cursor cursor = null;
        try {/*from   ww w  . ja va  2 s. c om*/
            cursor = resolver.query(uri, filePathColumn, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d"))
                        ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
                        : cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                if (columnIndex != -1) {
                    String filePath = cursor.getString(columnIndex);
                    if (!TextUtils.isEmpty(filePath)) {
                        return new File(filePath);
                    }
                }
            }
        } catch (SecurityException ignored) {
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    return null;
}

From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java

/**
 * Verifies the row the {@link Cursor} is pointing at, contains the same
 * information as that in the {@link ContentValues}.
 *
 * @param expectedValues values expected to be in the row.
 * @param valueCursor data to verify.//w w  w  .j a v a2 s.  c  o  m
 */
static void assertRowEquals(ContentValues expectedValues, Cursor valueCursor) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int columnIdx = valueCursor.getColumnIndex(columnName);
        Assert.assertTrue("Column '" + columnName + "' should exist.", columnIdx != -1);
        String expectedValue = entry.getValue().toString();
        Assert.assertEquals("Value must be equal to'" + expectedValue + "'.", expectedValue,
                valueCursor.getString(columnIdx));
    }
}

From source file:Main.java

public static File getFromMediaUri(ContentResolver resolver, Uri uri) {
    if (uri == null)
        return null;

    if (SCHEME_FILE.equals(uri.getScheme())) {
        return new File(uri.getPath());
    } else if (SCHEME_CONTENT.equals(uri.getScheme())) {
        final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME };
        Cursor cursor = null;
        try {/*from  w ww . j  a v a2  s. co m*/
            cursor = resolver.query(uri, filePathColumn, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d"))
                        ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
                        : cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                // Picasa image on newer devices with Honeycomb and up
                if (columnIndex != -1) {
                    String filePath = cursor.getString(columnIndex);
                    if (!TextUtils.isEmpty(filePath)) {
                        return new File(filePath);
                    }
                }
            }
        } catch (SecurityException ignored) {
            // Nothing we can do
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    return null;
}

From source file:cn.edu.mju.Thriphoto.net.NetStateManager.java

/**
 * ?? APN  {@link org.apache.http.HttpHost} 
 *
 * @return {@link org.apache.http.HttpHost} 
 *///w  ww  .  ja v a  2s .c om
public static HttpHost getAPN() {
    HttpHost proxy = null;
    Uri uri = Uri.parse("content://telephony/carriers/preferapn");
    Cursor mCursor = null;
    if (null != mContext) {
        mCursor = mContext.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) {
            proxy = new HttpHost(proxyStr, 80);
        }
        mCursor.close();
    }
    return proxy;
}

From source file:net.lamp.support.NetStateManager.java

/**
 * ?? APN ?{@link HttpHost} //from   ww  w . ja  v a  2 s.c o m
 * 
 * @return {@link HttpHost} 
 */
public static HttpHost getAPN() {
    HttpHost proxy = null;
    Uri uri = Uri.parse("content://telephony/carriers/preferapn");
    Cursor mCursor = null;
    if (null != mContext) {
        mCursor = mContext.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) {
            proxy = new HttpHost(proxyStr, 80);
        }
        mCursor.close();
    }
    return proxy;
}

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

/**
 * Helper method that converts the cursor to a destination object.
 *//*from  www .ja v  a 2  s .  c om*/
static Destination getCursorDestination(Cursor mCursor) {

    Destination d = new Destination();

    d.id = mCursor.getInt(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ID));
    d.identifier = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_IDENTIFIER));

    d.city = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_CITY));
    d.region = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_REGION));
    d.country = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_COUNTRY));

    d.arrival = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ARRIVAL));
    d.departure = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_DEPARTURE));

    double lat = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LAT));
    double lng = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LNG));
    d.position = new LatLng(lat, lng);

    d.presentsDelivered = mCursor
            .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTSDELIVERED));
    d.presentsDeliveredAtDestination = mCursor
            .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTS_DESTINATION));

    d.timezone = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_TIMEZONE));
    d.altitude = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ALTITUDE));
    d.photoString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PHOTOS));
    d.weatherString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_WEATHER));
    d.streetViewString = mCursor
            .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_STREETVIEW));

    d.gmmStreetViewString = mCursor
            .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_GMMSTREETVIEW));

    // Process the panoramio string if possible
    d.photos = processPhoto(d.photoString);
    d.weather = processWeather(d.weatherString);
    d.streetView = processStreetView(d.streetViewString);
    d.gmmStreetView = processStreetView(d.gmmStreetViewString);

    return d;
}

From source file:Main.java

public static String getRealFilePath(final Context context, final Uri uri) {
    if (null == uri)
        return null;
    final String scheme = uri.getScheme();
    String data = null;/*from  ww  w .j  a v  a 2  s  .  co m*/
    if (scheme == null)
        data = uri.getPath();
    else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
        data = uri.getPath();
    } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
        Cursor cursor = context.getContentResolver().query(uri,
                new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null);
        if (null != cursor) {
            if (cursor.moveToFirst()) {
                int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                if (index > -1) {
                    data = cursor.getString(index);
                }
            }
            cursor.close();
        }
    }
    return data;
}

From source file:com.rp.justcast.video.VideoProvider.java

public static List<MediaInfo> buildMedia() throws JSONException {

    if (null != mediaList) {
        return mediaList;
    }/*from   w  w w. j av  a2s.  c om*/

    String[] columns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.DURATION };
    String orderBy = MediaStore.Images.Media.DATE_TAKEN + " desc";
    Cursor videoCursor = null;
    try {
        videoCursor = JustCast.getmAppContext().getContentResolver()
                .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
        videoCursor.moveToFirst();
        long fileId = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media._ID));
        Log.w(TAG, "Building Media");
        Log.w(TAG, "Video Count" + videoCursor.getCount());
        int count = videoCursor.getCount();
        Log.d(TAG, "Count of images" + count);
        mediaList = new ArrayList<MediaInfo>();
        for (int i = 0; i < count; i++) {
            videoCursor.moveToPosition(i);
            int dataColumnIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA);
            int titleIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.TITLE);
            Log.w(TAG, "Video added" + videoCursor.getString(dataColumnIndex));
            String path = videoCursor.getString(dataColumnIndex);
            String title = videoCursor.getString(titleIndex);
            MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
            movieMetadata.putString("VIDEO_PATH", path);
            movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_STUDIO, title);
            path = JustCast.addJustCastServerParam(path);
            MediaInfo mediaInfo = new MediaInfo.Builder(path).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                    .setContentType(getMediaType()).setMetadata(movieMetadata).build();
            mediaList.add(mediaInfo);
        }
    } finally {
        videoCursor.close();
    }
    return mediaList;
}