當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。