Example usage for android.database Cursor getColumnIndexOrThrow

List of usage examples for android.database Cursor getColumnIndexOrThrow

Introduction

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

Prototype

int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;

Source Link

Document

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

Usage

From source file:com.gsma.rcs.ri.messaging.geoloc.DisplayGeoloc.java

private static Geoloc getMyLastGeoloc(Context ctx) {
    Cursor cursor = null;
    try {//from w w  w  .j  a  v a2  s . c  om
        cursor = ctx.getContentResolver().query(Message.CONTENT_URI, QUERY_PROJECTION, QUERY_WHERE_CLAUSE, null,
                QUERY_SORT_ORDER);
        if (cursor == null) {
            throw new SQLException("Cannot query my last geoloc");
        }
        if (!cursor.moveToNext()) {
            return null;
        }
        String content = cursor.getString(cursor.getColumnIndexOrThrow(Message.CONTENT));
        return new Geoloc(content);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.duy.pascal.ui.file.FileManager.java

/**
 * get path from uri//from www.j a  v  a  2  s .  c  om
 */
@Nullable
public static String getPathFromUri(Context context, Uri uri) throws URISyntaxException {
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor;
        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            if (cursor == null) {
                return null;
            }
            int index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                String path = cursor.getString(index);
                cursor.close();
                return path;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}

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   w  w  w  .j  a v  a2  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;
    }/*from www.j  a  v  a2  s .  c  o m*/
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

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
 * //w  ww  .j av  a  2 s  .  co 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.hivewallet.androidclient.wallet.AddressBookProvider.java

public static AddressBookEntry lookupEntry(final Context context, @Nonnull final String address) {
    String label = null;/*from  w ww.  j av  a2  s.  c om*/
    String photo = null;

    final Uri uri = contentUri(context.getPackageName()).buildUpon().appendPath(address).build();
    final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    if (cursor != null) {
        if (cursor.moveToFirst()) {
            label = cursor.getString(cursor.getColumnIndexOrThrow(KEY_LABEL));
            photo = cursor.getString(cursor.getColumnIndexOrThrow(KEY_PHOTO));
        }

        cursor.close();
    }

    if (label != null) {
        return new AddressBookEntry(address, label, photo);
    } else {
        return null;
    }
}

From source file:com.energysystem.videoexplorerTV.video.VideoProvider.java

public static HashMap<String, List<Video>> buildMedia(String url, Cursor data) throws JSONException {

    mMovieList = new HashMap<String, List<Video>>();
    mMovieList.clear();/*w  ww .j  av a  2  s. co m*/
    Log.e("Abrimos", "Videos");
    List<Video> categoryList = new ArrayList<Video>();
    List<Video> categoryList2 = new ArrayList<Video>();

    while (data.moveToNext()) {
        int videoID = data.getInt(data.getColumnIndex(MediaStore.Video.Media._ID));
        int title = data.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE);
        int category = data.getColumnIndexOrThrow(MediaStore.Video.Media.CATEGORY);
        int durationID = data.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
        int data_string = data.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        //int videoUrl = data.getColumnIndexOrThrow(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString());
        // int bgImageUrl = data.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI.toString());

        int duration = Integer.parseInt(data.getString(durationID));

        String categoria = new File(data.getString(data_string)).getParent();
        Log.e("Ruta:", categoria);
        if (categoria.equals("/storage/emulated/0/Movies")) {
            categoryList.add(buildMovieInfo(categoria, data.getString(title), "Descripcion",
                    String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration),
                            TimeUnit.MILLISECONDS.toSeconds(duration)
                                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID)
                            .toString()));
            mMovieList.put("Almacenamiento Interno", categoryList);
        } else {
            categoryList2.add(buildMovieInfo(categoria, data.getString(title), "Descripcion",
                    String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration),
                            TimeUnit.MILLISECONDS.toSeconds(duration)
                                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID)
                            .toString()));
            mMovieList.put("USB", categoryList2);
        }
    }

    /*JSONObject jsonObj = new VideoProvider().parseUrl(url);
    JSONArray categories = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS);
    if (null != categories) {
    Log.d(TAG, "category #: " + categories.length());
    String title;
    String videoUrl;
    String bgImageUrl;
    String cardImageUrl;
    String studio;
    for (int i = 0; i < categories.length(); i++) {
        JSONObject category = categories.getJSONObject(i);
        String category_name = category.getString(TAG_CATEGORY);
        JSONArray videos = category.getJSONArray(TAG_MEDIA);
        Log.d(TAG,
                "category: " + i + " Name:" + category_name + " video length: "
                        + videos.length());
        List<Video> categoryList = new ArrayList<Video>();
        if (null != videos) {
            for (int j = 0; j < videos.length(); j++) {
                JSONObject video = videos.getJSONObject(j);
                String description = video.getString(TAG_DESCRIPTION);
                JSONArray videoUrls = video.getJSONArray(TAG_SOURCES);
                if (null == videoUrls || videoUrls.length() == 0) {
                    continue;
                }
                title = video.getString(TAG_TITLE);
                videoUrl = getVideoPrefix(category_name, videoUrls.getString(0));
                bgImageUrl = getThumbPrefix(category_name, title,
                        video.getString(TAG_BACKGROUND));
                cardImageUrl = getThumbPrefix(category_name, title,
                        video.getString(TAG_CARD_THUMB));
                studio = video.getString(TAG_STUDIO);
                categoryList.add(buildMovieInfo(category_name, title, description, studio,
                        videoUrl, cardImageUrl,
                        bgImageUrl));
            }
            mMovieList.put(category_name, categoryList);
        }
    }
    }*/
    Log.e("VideoProvider", "Tamano mMovie: " + mMovieList.size());
    return mMovieList;
}

From source file:com.gsma.rcs.ri.messaging.filetransfer.FileTransferIntentService.java

/**
 * Get set of undelivered file transfers
 *
 * @param ctx The context//from  www. j a va 2 s  .co  m
 * @param contact The contact
 * @return set of undelivered file transfers
 */
public static Set<String> getUndelivered(Context ctx, ContactId contact) {
    Set<String> ids = new HashSet<>();
    Cursor cursor = null;
    try {
        cursor = ctx.getContentResolver().query(FileTransferLog.CONTENT_URI, PROJ_UNDELIVERED_FT,
                SEL_UNDELIVERED_FTS, new String[] { contact.toString() }, null);
        if (cursor == null) {
            throw new SQLException("Cannot query undelivered file transfers for contact=" + contact);
        }
        if (!cursor.moveToFirst()) {
            return ids;
        }
        int idColumnIdx = cursor.getColumnIndexOrThrow(FileTransferLog.FT_ID);
        do {
            ids.add(cursor.getString(idColumnIdx));
        } while (cursor.moveToNext());
        return ids;

    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService.java

/**
 * Get set of undelivered messages//from  w w w .  j  a va2 s  .c  o  m
 *
 * @param ctx The context
 * @param contact The contact
 * @return set of undelivered messages
 */
public static Set<String> getUndelivered(Context ctx, ContactId contact) {
    Set<String> messageIds = new HashSet<>();
    Cursor cursor = null;
    try {
        cursor = ctx.getContentResolver().query(ChatLog.Message.CONTENT_URI, PROJ_UNDELIVERED_MSG,
                SEL_UNDELIVERED_MESSAGES, new String[] { contact.toString() }, null);
        if (cursor == null) {
            throw new SQLException("Cannot query undelivered message for contact=" + contact);
        }
        if (!cursor.moveToFirst()) {
            return messageIds;
        }
        int messageIdColumnIdx = cursor.getColumnIndexOrThrow(ChatLog.Message.MESSAGE_ID);
        do {
            messageIds.add(cursor.getString(messageIdColumnIdx));
        } while (cursor.moveToNext());
        return messageIds;

    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:foam.zizim.android.BoskoiService.java

public static CategoriesData[] getCategoriesDetails(String categoryIds) {

    String[] categories = categoryIds.split(",");
    CategoriesData result[] = new CategoriesData[categories.length];

    int i = 0;/*from  ww  w  .  j  a va  2  s  .c  o m*/

    for (String categoryId : categories) {
        Cursor cursor = BoskoiApplication.mDb.fetchCategoriesById(Integer.parseInt(categoryId));

        if (cursor.moveToFirst()) {
            int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE);
            int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL);
            int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA);
            int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID);
            int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID);
            int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR);
            int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC);

            CategoriesData cat = new CategoriesData();
            cat.setCategoryId(cursor.getInt(idIndex));
            cat.setCategoryTitle(cursor.getString(titleIndex));
            cat.setCategoryTitleNL(cursor.getString(titleNL));
            cat.setCategoryTitleLA(cursor.getString(titleLA));
            cat.setCategoryParentId(cursor.getInt(parentId));
            cat.setCategoryColor(cursor.getString(color));
            cat.setCategoryDescription(cursor.getString(desc));

            result[i] = cat;

            i++;
        }

        cursor.close();
    }
    return result;
}