Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

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

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java

/**
 * Queries the media store to find out what the file path is for the Uri we supply
 *
 * @param contentUri the Uri of the audio/image/video
 * @param  cordova) the current applicaiton context
 * @return the full path to the file/*from w ww  .  j a v  a  2  s  .c om*/
 */
@SuppressWarnings("deprecation")
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) {
    String[] proj = { _DATA };
    Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(_DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a String out of a field in a Cursor and writes it to an InsertHelper.
 *
 * @param cursor The cursor to read from
 * @param field The TEXT field to read//  ww  w . j  a  v a2  s.c  o  m
 * @param inserter The InsertHelper to bind into
 * @param index the index of the bind entry in the InsertHelper
 */
public static void cursorStringToInsertHelper(Cursor cursor, String field, InsertHelper inserter, int index) {
    inserter.bind(index, cursor.getString(cursor.getColumnIndexOrThrow(field)));
}

From source file:Main.java

/**
 * Retourner la liste des calendriers/*w  w w  . jav  a2  s  .c  o  m*/
 * 
 * @return Liste des calendriers
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static Map<Integer, String> getCalendars(ContentResolver contentResolver) {
    Map<Integer, String> calendars = new HashMap<Integer, String>();
    String[] projection;
    Uri calendarUri;
    Cursor cursor;
    String accessLevelCol;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        calendarUri = CalendarContract.Calendars.CONTENT_URI;
        projection = new String[] { CalendarContract.Calendars._ID,
                CalendarContract.Calendars.CALENDAR_DISPLAY_NAME };
        accessLevelCol = CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        calendarUri = Uri.parse("content://com.android.calendar/calendars");
        projection = new String[] { "_id", "displayname" };
        accessLevelCol = "ACCESS_LEVEL";
    } else {
        calendarUri = Uri.parse("content://calendar/calendars");
        projection = new String[] { "_id", "displayname" };
        accessLevelCol = "ACCESS_LEVEL";
    }

    cursor = contentResolver.query(calendarUri, projection, accessLevelCol + "=700", null, null);

    if (cursor != null && cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
            calendars.put(cursor.getInt(0), cursor.getString(1));
            cursor.moveToNext();
        }
        cursor.close();
    }

    return calendars;
}

From source file:com.manning.androidhacks.hack023.adapter.TodoAdapter.java

@Override
public void bindView(View view, Context context, Cursor c) {
    final ViewHolder holder = (ViewHolder) view.getTag();
    holder.id.setText(c.getString(mInternalIdIndex));
    holder.title.setText(c.getString(mTitleIndex));

    final int status = c.getInt(mInternalStatusIndex);
    if (StatusFlag.CLEAN != status) {
        holder.title.setBackgroundColor(Color.RED);
    } else {//from   w  w w .  java  2  s.  c o m
        holder.title.setBackgroundColor(Color.GREEN);
    }

    final Long id = Long.valueOf(holder.id.getText().toString());
    holder.deleteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TodoDAO.getInstance().deleteTodo(mActivity.getContentResolver(), id);
        }
    });

}

From source file:com.orm.androrm.migration.MigrationHelper.java

/**
 * Checks whether a given table name already exists in the database.
 * //from w w w .  j  av  a2 s  .  co m
 * @param name Name of the table to look up.
 * @return <code>true</code> if one exists <code>false</code> otherwise.
 */
public boolean tableExists(String name) {
    String sql = "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '" + name + "'";

    Cursor c = getCursor(sql);

    while (c.moveToNext()) {
        String table = c.getString(c.getColumnIndexOrThrow("name"));

        if (table.equalsIgnoreCase(name)) {
            close(c);

            return true;
        }
    }

    close(c);
    return false;
}

From source file:com.orm.androrm.migration.MigrationHelper.java

public List<String> getRelationTableNames(String table) {
    List<String> result = new ArrayList<String>();
    String sql = "SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '" + table
            + "#_%' OR name LIKE '%#_" + table + "' ESCAPE '#')";

    Cursor c = getCursor(sql);

    while (c.moveToNext()) {
        String name = c.getString(c.getColumnIndexOrThrow("name"));

        if (!name.equalsIgnoreCase(table) && (StringUtils.startsWithIgnoreCase(name, table)
                || StringUtils.endsWithIgnoreCase(name, table))) {

            result.add(name);/*from   w  ww . jav  a  2  s .c o  m*/
        }
    }

    close(c);
    return result;
}

From source file:com.orm.androrm.migration.MigrationHelper.java

public boolean hasField(Class<? extends Model> model, String name) {
    String table = DatabaseBuilder.getTableName(model);
    String sql = "PRAGMA TABLE_INFO(`" + table + "`)";

    Cursor c = getCursor(sql);

    while (c.moveToNext()) {
        String fieldName = c.getString(c.getColumnIndexOrThrow("name"));

        if (fieldName.equals(name)) {
            close(c);/*from w w w  .  j a va 2 s  .  c  o  m*/
            return true;
        }
    }

    close(c);
    return false;
}

From source file:Main.java

/**
 * Try to get the exif orientation of the passed image uri
 * //ww  w  .  ja v  a 2 s . c  o  m
 * @param context
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {

    final String scheme = uri.getScheme();

    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            return 0;
        }

        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri,
                        new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null,
                        null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }

            if (result == null) {
                return 0;
            }

            int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA);

            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();

                    int rotation = 0;

                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }

                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    return 0;
}

From source file:com.digitalarx.android.syncadapter.ContactSyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from   www  . jav  a  2s.com
    setAccount(account);
    setContentProviderClient(provider);
    Cursor c = getLocalContacts(false);
    if (c.moveToFirst()) {
        do {
            String lookup = c.getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
            String a = getAddressBookUri();
            String uri = a + lookup + ".vcf";
            FileInputStream f;
            try {
                f = getContactVcard(lookup);
                HttpPut query = new HttpPut(uri);
                byte[] b = new byte[f.available()];
                f.read(b);
                query.setEntity(new ByteArrayEntity(b));
                fireRawRequest(query);
            } catch (IOException e) {
                e.printStackTrace();
                return;
            } catch (OperationCanceledException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (AuthenticatorException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } while (c.moveToNext());
        // } while (c.moveToNext());
    }

}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getReadMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    HashSet<String> readSet = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_id FROM headers WHERE read=1 AND subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        readSet = new HashSet<String>(c.getCount());
        c.moveToFirst();//from   w  ww. j  a v  a 2  s.co  m

        for (int i = 0; i < count; i++) {
            readSet.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (readSet == null)
        readSet = new HashSet<String>(0);
    return readSet;
}