List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:com.clevertrail.mobile.Database_SavedTrails.java
public String getJSONString(String sName) { String[] columns = new String[] { "json" }; String selection = "name = '" + sName + "'"; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, selection, null, null, null, null); cursor.moveToFirst();/*w w w.java 2 s . c o m*/ int index_JSON = cursor.getColumnIndex("json"); String sReturn = ""; if (!cursor.isAfterLast()) sReturn = cursor.getString(index_JSON); return sReturn; }
From source file:com.liferay.alerts.database.DatabaseHelper.java
private void _convertMessageToJSONObject(SQLiteDatabase database) { StringBuilder select = new StringBuilder(); select.append("SELECT "); select.append(Alert.ID);/*from ww w. j a v a 2s . c o m*/ select.append(", "); select.append(Alert.PAYLOAD); select.append(" FROM "); select.append(AlertDAO.TABLE_NAME); Cursor cursor = database.rawQuery(select.toString(), null); while (cursor.moveToNext()) { try { long id = cursor.getLong(cursor.getColumnIndex(Alert.ID)); String payload = cursor.getString(cursor.getColumnIndex(Alert.PAYLOAD)); JSONObject jsonObject = new JSONObject(); jsonObject.put(Alert.MESSAGE, payload); ContentValues values = new ContentValues(); values.put(Alert.PAYLOAD, jsonObject.toString()); StringBuilder sb = new StringBuilder(); sb.append(Alert.ID); sb.append(CharPool.SPACE); sb.append("= ?"); String whereClause = sb.toString(); String[] whereArgs = { String.valueOf(id) }; database.update(AlertDAO.TABLE_NAME, values, whereClause, whereArgs); } catch (JSONException je) { Log.e(_TAG, "Couldn't convert message.", je); } } }
From source file:com.clevertrail.mobile.Database_SavedTrails.java
public String getJSONString() { String[] columns = new String[] { "json" }; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null); cursor.moveToFirst();//ww w . j a v a2 s. co m int index_JSON = cursor.getColumnIndex("json"); //we will create a simple return value of the format: //"[trail1JSON, trail2JSON, ...]" String sReturn = "["; while (!cursor.isAfterLast()) { String sTrailJSON = cursor.getString(index_JSON); sReturn = sReturn.concat(sTrailJSON); cursor.moveToNext(); if (!cursor.isAfterLast()) { if (sTrailJSON.compareTo("") != 0) sReturn = sReturn.concat(","); } else { break; } } sReturn = sReturn.concat("]"); return sReturn; }
From source file:cc.vileda.sipgatesync.contacts.SipgateContactSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/* ww w .j a v a 2 s. c om*/ Log.d("SipgateContactSyncAdapt", "onPerformSync()"); AccountManager accountManager = AccountManager.get(getContext()); final String oauth = accountManager.peekAuthToken(account, "oauth"); Log.d("SipgateContactSyncAdapt", oauth == null ? "NO oauth!" : "Got token"); final JSONArray users = SipgateApi.getContacts(oauth); assert users != null; Log.d("SipgateContactSyncAdapt", String.format("fetched %d contacts", users.length())); Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type).build(); Cursor c1 = mContentResolver.query(rawContactUri, null, null, null, null); Map<String, Boolean> localContacts = new HashMap<>(); while (c1 != null && c1.moveToNext()) { localContacts.put(c1.getString(c1.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID)), false); } for (int i = 0; i < users.length(); i++) { try { final JSONObject user = users.getJSONObject(i); final String id = user.getString("uuid"); if (localContacts.containsKey(id)) { localContacts.put(id, true); continue; } final String firstname = user.getString("firstname"); final JSONArray emails = user.getJSONArray("emails"); final JSONArray mobile = user.getJSONArray("mobile"); final JSONArray landline = user.getJSONArray("landline"); final JSONArray fax = user.getJSONArray("fax"); Log.d("SipgateContactSyncAdapt", String.format("adding id: %s %s", id, firstname)); ContactManager.addContact(id, firstname, user.getString("lastname"), jsonArrayToList(emails), jsonArrayToList(mobile), jsonArrayToList(landline), jsonArrayToList(fax), mContentResolver, account.name); } catch (JSONException e) { e.printStackTrace(); } } for (Map.Entry<String, Boolean> contact : localContacts.entrySet()) { if (!contact.getValue()) { ContactManager.deleteContact(contact.getKey(), mContentResolver, account.name); } } }
From source file:com.phicomm.account.operator.GetMapOperation.java
@Override public Bundle execute(Context context, Request request) { String ssession_id = null;//from w w w . ja v a2s. co m Bundle resultData = new Bundle(); Cursor persionCursor = context.getContentResolver().query(Provider.PersonColumns.CONTENT_URI, null, null, null, null); if (persionCursor != null) { if (persionCursor.moveToFirst()) { ssession_id = persionCursor .getString(persionCursor.getColumnIndex(Provider.PersonColumns.JSSESSIONID)); } persionCursor.close(); } String url = WSConfig.WS_GET_MAP_URL + ssession_id; NetworkConnection networkConnection1 = new NetworkConnection(context, url); ArrayList<BasicNameValuePair> parameterList = new ArrayList<BasicNameValuePair>(); BasicNameValuePair value = new BasicNameValuePair("XML", ""); parameterList.add(value); networkConnection1.setParameters(parameterList); try { ConnectionResult result = networkConnection1.execute(); resultData.putString("result", result.body); Log.i("ss", "map________________________________result.body:" + result.body); } catch (ConnectionException e) { e.printStackTrace(); } Log.i("ss", "_______________________________________OK"); return resultData; }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testCrashReport() throws Exception { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); // Log a test (fake) crash report. Checkin.reportCrash(r, new CrashData("Test", "Test Activity", new BuildData("Test Build", "123", start), new ThrowableData(new RuntimeException("Test Exception")))); // Crashes aren't indexed; go through them all to find the one we added. Cursor c = r.query(Checkin.Crashes.CONTENT_URI, null, null, null, null); Uri uri = null;//from ww w . j a va 2 s . co m while (c.moveToNext()) { String coded = c.getString(c.getColumnIndex(Checkin.Crashes.DATA)); byte[] bytes = Base64.decodeBase64(coded.getBytes()); CrashData crash = new CrashData(new DataInputStream(new ByteArrayInputStream(bytes))); // Should be exactly one recently added "Test" crash. if (crash.getId().equals("Test") && crash.getTime() > start) { assertEquals("Test Activity", crash.getActivity()); assertEquals("Test Build", crash.getBuildData().getFingerprint()); assertEquals("Test Exception", crash.getThrowableData().getMessage()); assertNull(uri); uri = ContentUris.withAppendedId(Checkin.Crashes.CONTENT_URI, c.getInt(c.getColumnIndex(Checkin.Crashes._ID))); } } assertNotNull(uri); c.close(); // Update the "logs" column. ContentValues values = new ContentValues(); values.put(Checkin.Crashes.LOGS, "Test Logs"); assertEquals(1, r.update(uri, values, null, null)); c = r.query(uri, null, null, null, null); assertTrue(c.moveToNext()); String logs = c.getString(c.getColumnIndex(Checkin.Crashes.LOGS)); assertEquals("Test Logs", logs); c.deleteRow(); c.close(); c.requery(); assertFalse(c.moveToNext()); c.close(); }
From source file:br.ufc.mdcc.benchimage2.dao.ResultDao.java
private ArrayList<ResultImage> queryResultImage(String sql) throws JSONException, ParseException { openDatabase();/*from w w w. java 2 s .c om*/ Cursor cursor = database.rawQuery(sql, null); ArrayList<ResultImage> lista = new ArrayList<ResultImage>(); // obtem todos os indices das colunas da tabela int idx_id = cursor.getColumnIndex(F_ID); int idx_date = cursor.getColumnIndex(F_DATE); int idx_photo_name = cursor.getColumnIndex(F_PHOTO_NAME); int idx_filter_name = cursor.getColumnIndex(F_FILTER_NAME); int idx_local = cursor.getColumnIndex(F_LOCAL); int idx_size = cursor.getColumnIndex(F_SIZE); int idx_cpu_time = cursor.getColumnIndex(F_EXECUTION_CPU_TIME); int idx_up_time = cursor.getColumnIndex(F_UPLOAD_TIME); int idx_down_time = cursor.getColumnIndex(F_DOWNLOAD_TIME); int idx_total_time = cursor.getColumnIndex(F_TOTAL_TIME); int idx_down_size = cursor.getColumnIndex(F_DOWN_SIZE); int idx_up_size = cursor.getColumnIndex(F_UP_SIZE); if (cursor != null && cursor.moveToFirst()) { do { ResultImage result = new ResultImage(); result.setId(cursor.getInt(idx_id)); result.setDate(simpleDateFormat.parse(cursor.getString(idx_date))); result.setTotalTime(cursor.getLong(idx_total_time)); AppConfiguration config = new AppConfiguration(); config.setImage(cursor.getString(idx_photo_name)); config.setFilter(cursor.getString(idx_filter_name)); config.setLocal(cursor.getString(idx_local)); config.setSize(cursor.getString(idx_size)); result.setConfig(config); RpcProfile profile = new RpcProfile(); profile.setDonwloadTime(cursor.getLong(idx_down_time)); profile.setDownloadSize(cursor.getInt(idx_down_size)); profile.setUploadTime(cursor.getLong(idx_up_time)); profile.setUploadSize(cursor.getInt(idx_up_size)); profile.setExecutionCpuTime(cursor.getLong(idx_cpu_time)); result.setRpcProfile(profile); lista.add(result); } while (cursor.moveToNext()); } cursor.close(); closeDatabase(); return lista; }
From source file:com.zoterodroid.activity.BrowseCitations.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_bookmarks); mAccountManager = AccountManager.get(this); mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0]; mContext = this; Log.d("browse bookmarks", getIntent().getDataString()); Uri data = getIntent().getData();//from w w w .j a v a 2 s .c o m String scheme = data.getScheme(); String path = data.getPath(); Log.d("path", path); String username = data.getQueryParameter("username"); String tagname = data.getQueryParameter("tagname"); String recent = data.getQueryParameter("recent"); myself = mAccount.name.equals(username); ArrayList<Citation> citationList = new ArrayList<Citation>(); if (scheme.equals("content") && path.equals("/citations") && myself) { try { String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key, Citation.Creator_Summary, Citation.Item_Type }; String selection = null; String sortorder = null; selection = Citation.Account + " = '" + username + "'"; Uri citations = Citation.CONTENT_URI; Cursor c = managedQuery(citations, projection, selection, null, sortorder); if (c.moveToFirst()) { int idColumn = c.getColumnIndex(Citation._ID); int titleColumn = c.getColumnIndex(Citation.Title); int keyColumn = c.getColumnIndex(Citation.Key); int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary); int itemTypeColumn = c.getColumnIndex(Citation.Item_Type); do { Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn), c.getString(keyColumn), c.getString(creatorSummaryColumn), c.getString(itemTypeColumn)); citationList.add(b); } while (c.moveToNext()); } setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList)); } catch (Exception e) { } } lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); /* Add Context-Menu listener to the ListView. */ lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("Actions"); if (myself) { menu.add(Menu.NONE, 0, Menu.NONE, "Delete"); } else { menu.add(Menu.NONE, 1, Menu.NONE, "Add"); } } }); }
From source file:edu.mit.mobile.android.demomode.Preferences.java
private String toConfigString() { final String password = mPrefs.getString(KEY_PASSWORD, null); final ArrayList<BasicNameValuePair> nvp = new ArrayList<BasicNameValuePair>(); int ver;/*w w w.java 2s . c o m*/ try { ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (final NameNotFoundException e) { // this should never happen ver = 0; e.printStackTrace(); } nvp.add(new BasicNameValuePair(CFG_K_VER, String.valueOf(ver))); nvp.add(new BasicNameValuePair(CFG_K_SECRETKEY, password)); final Cursor c = getContentResolver().query(LauncherItem.CONTENT_URI, null, null, null, null); try { final int pkgCol = c.getColumnIndex(LauncherItem.PACKAGE_NAME); final int actCol = c.getColumnIndex(LauncherItem.ACTIVITY_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { nvp.add(new BasicNameValuePair(CFG_K_APPS, c.getString(pkgCol) + CFG_PKG_SEP + c.getString(actCol))); } return "data:" + CFG_MIME_TYPE + "," + URLEncodedUtils.format(nvp, "utf-8"); } finally { c.close(); } }
From source file:be.vbsteven.bmtodesk.SendAllCurrentBookmarksActivity.java
protected ArrayList<Bookmark> getAllBookmarks() { ArrayList<Bookmark> result = new ArrayList<SendAllCurrentBookmarksActivity.Bookmark>(); String[] projection = new String[] { BookmarkColumns.TITLE, BookmarkColumns.URL }; Cursor c = managedQuery(Browser.BOOKMARKS_URI, projection, "bookmark = ?", new String[] { "1" }, null); if (c.moveToFirst()) { int title = c.getColumnIndex(BookmarkColumns.TITLE); int url = c.getColumnIndex(BookmarkColumns.URL); while (!c.isAfterLast()) { Bookmark b = new Bookmark(); b.title = c.getString(title); b.url = c.getString(url);/*from w ww . j a v a2s . c o m*/ result.add(b); c.moveToNext(); } } return result; }