当前位置: 首页>>代码示例>>Java>>正文


Java Cursor.getColumnIndexOrThrow方法代码示例

本文整理汇总了Java中android.database.Cursor.getColumnIndexOrThrow方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.getColumnIndexOrThrow方法的具体用法?Java Cursor.getColumnIndexOrThrow怎么用?Java Cursor.getColumnIndexOrThrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.Cursor的用法示例。


在下文中一共展示了Cursor.getColumnIndexOrThrow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRealPath

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:34,代码来源:FileHelper.java

示例2: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
@Nullable private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
开发者ID:customerly,项目名称:Customerly-Android-SDK,代码行数:17,代码来源:IU_Utils.java

示例3: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
public static String getDataColumn(@NonNull Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String column = MediaStore.Images.Media.DATA;
    String[] projection = {column};
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
开发者ID:Jusenr,项目名称:zxing_qrcode_demo,代码行数:17,代码来源:CodeUtils.java

示例4: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        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;
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:32,代码来源:CropFileUtils.java

示例5: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
	Cursor cursor = null;
	String column = MediaStore.Images.Media.DATA;
	String[] projection = { column };
	try {
		cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
		if (cursor != null && cursor.moveToFirst()) {
			int index = cursor.getColumnIndexOrThrow(column);
			return cursor.getString(index);
		}
	} finally {
		if (cursor != null)
			cursor.close();
	}
	return null;
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:17,代码来源:StaticMethod.java

示例6: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
开发者ID:rumaan,项目名称:file.io-app,代码行数:37,代码来源:FileUtils.java

示例7: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            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;
    }
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:21,代码来源:PathUtils.java

示例8: a

import android.database.Cursor; //导入方法依赖的package包/类
private Uri a(Intent intent) {
    Cursor query = this.e.getContentResolver().query(intent.getData(), new String[]{"_data"},
            null, null, null);
    if (query == null) {
        return null;
    }
    int columnIndexOrThrow = query.getColumnIndexOrThrow("_data");
    query.moveToFirst();
    String string = query.getString(columnIndexOrThrow);
    if (string != null && (string.endsWith(".png") || string.endsWith(".PNG") || string
            .endsWith(".jpg") || string.endsWith(".JPG"))) {
        return Uri.fromFile(e.b(string, this.b.c));
    }
    query.close();
    return null;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:WebViewActivity.java

示例9: getAlbumArtsFromArtist

import android.database.Cursor; //导入方法依赖的package包/类
public static Uri[] getAlbumArtsFromArtist(Context context, long artistId) {

		final Uri uri = MusicStore.Audio.Artists.Albums.getContentUri("external", artistId);
		final String sortOrder = MusicStore.Audio.Media.YEAR + DESC;
		StringBuilder where = new StringBuilder();
		where.append(MusicStore.Audio.Artists.Albums.ALBUM_ART).append(" != ''");

		Cursor c = query(context,uri, ALBUM_COLS, where.toString(), null, sortOrder);
		if (c==null) return null;

		Uri result[] = new Uri[c.getCount()];

		final int albumIdIdx = c.getColumnIndexOrThrow(MusicStore.Audio.Albums._ID);

		c.moveToFirst();
		int n=0;
		while (!c.isAfterLast() && (n<result.length)) { // better safe than sorry
			result[n++] = ContentUris.withAppendedId(ALBUM_ARTWORK_URI, c.getLong(albumIdIdx));
			c.moveToNext();
		}

		return result;
	}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:24,代码来源:LibraryUtils.java

示例10: getRealPathFromURI

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Extract the path from an uri
 * This code was published on StackOverflow by dextor
 *
 * @param contentUri		uri that contains the file path
 * @return absolute file path as string
 */
private String getRealPathFromURI(Uri contentUri) {
	String[] proj = { MediaStore.Images.Media.DATA };
	CursorLoader loader = new CursorLoader(this.getActivity(), contentUri, proj, null, null, null);
	Cursor cursor = loader.loadInBackground();
	int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
	cursor.moveToFirst();
	return cursor.getString(column_index);
}
 
开发者ID:takyonxxx,项目名称:AndroidSdrRtlTuner,代码行数:16,代码来源:SettingsFragment.java

示例11: getDataColumn

import android.database.Cursor; //导入方法依赖的package包/类
static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String[] projection = {MediaStore.Images.Media.DATA};
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:16,代码来源:AgentWebUtils.java

示例12: addEncryptedStringToStatement

import android.database.Cursor; //导入方法依赖的package包/类
private static void addEncryptedStringToStatement(Context context, SQLiteStatement statement,
                                                  Cursor cursor, MasterSecret masterSecret,
                                                  int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, encrypt(masterSecret, cursor.getString(columnIndex)));
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:13,代码来源:SmsMigrator.java

示例13: getRealPathFromURI_BelowAPI11

import android.database.Cursor; //导入方法依赖的package包/类
public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;

    try {
        Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);

    } catch (Exception e) {
        result = null;
    }
    return result;
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:16,代码来源:FileHelper.java

示例14: swapCursor

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Swap in a new Cursor, returning the old Cursor.  Unlike
 * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
 * closed.
 *
 * @param newCursor The new cursor to be used.
 * @return Returns the previously set Cursor, or null if there wasa not one.
 * If the given new Cursor is the same instance is the previously set
 * Cursor, null is also returned.
 */
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == mCursor) {
        return null;
    }
    Cursor oldCursor = mCursor;
    if (oldCursor != null) {
        if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
        if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }
    mCursor = newCursor;
    if (newCursor != null) {
        if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
        mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        mDataValid = true;
        // notify the observers about the new cursor
        notifyDataSetChanged();
    } else {
        mRowIDColumn = -1;
        mDataValid = false;
        // notify the observers about the lack of a data set
        // notifyDataSetInvalidated();
        notifyItemRangeRemoved(0, oldCursor.getCount());
    }
    return oldCursor;
}
 
开发者ID:vikasdesale,项目名称:News24x7-news-from-every-part-of-the-world,代码行数:37,代码来源:CursorRecyclerViewAdapter.java

示例15: getPathFromUri

import android.database.Cursor; //导入方法依赖的package包/类
public String getPathFromUri(Uri uri) {
    String[] projection = {MediaStore.Images.Media.DATA};
    Cursor cursor = this.getContentResolver().query(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:8,代码来源:CreateACActivity.java


注:本文中的android.database.Cursor.getColumnIndexOrThrow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。