List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:org.blanco.techmun.android.MensajesActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0 && resultCode == RESULT_OK) { Cursor c = managedQuery(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_id = " + 1, null, null); if (c != null && c.moveToNext()) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst();//from w w w. j ava 2 s . c om int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); attachImage = BitmapFactory.decodeFile(filePath); //Mark the button as image attached btnAddImage.setBackgroundColor(Color.YELLOW); Log.i("techmun", "selected image" + filePath + " Loaded."); } Log.d("techmun", "Returned from image pick"); } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.openerp.base.res.Res_PartnerSyncHelper.java
public Uri getPartnerUri(int partner_id) { Account account = OpenERPAccountManager.getAccount(mContext, OEUser.current(mContext).getAndroidName()); Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(); mContentResolver = mContext.getContentResolver(); Cursor data = mContentResolver.query(rawContactUri, null, SYNC1_PARTNER_ID + " = " + partner_id, null, null);//from w w w . j a v a 2s .c om String contact_raw_id = null; while (data.moveToNext()) { contact_raw_id = data.getString(data.getColumnIndex(ContactsContract.Contacts._ID)); } data.close(); Uri contact_uri = null; if (contact_raw_id != null) { contact_uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contact_raw_id); } return contact_uri; }
From source file:it.ms.theing.loquitur.functions.PhoneDir.java
/** * This function returns the best matching object * @return/*from w w w. j a v a 2 s . co m*/ * structure : { name:... , phone: ... , email: ... } */ @JavascriptInterface public String match(String compare, float minscore) { Cursor cursor = null; try { JSONArray obj = new JSONArray(); cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); String ID = null; String name = null; while (cursor.moveToNext()) { String nam = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); float score = Utils.match(nam, compare); if (score > minscore) { minscore = score; ID = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); name = nam; } } cursor.close(); cursor = null; if (ID == null) return ""; String phone = getPhone(ID); String email = getEmail(ID); JSONObject jo = new JSONObject(); jo.put("name", name.toLowerCase()); jo.put("phone", phone); jo.put("email", email); return jo.toString(); } catch (Exception e) { Utils.safe(e); } if (cursor != null) { try { cursor.close(); } catch (Exception e) { } } return ""; }
From source file:com.example.gaurav.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from ww w. ja va2s . c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI long rowId; final ContentResolver resolver = mContext.getContentResolver(); Uri uri = Uri.parse(WeatherContract.BASE_CONTENT_URI + "/" + WeatherContract.PATH_LOCATION); String selectionArgs[] = { WeatherContract.LocationEntry.COLUMN_CITY_NAME }; String selection = WeatherContract.LocationEntry.COLUMN_CITY_NAME + " =? "; //First, query database to check if this location already exists. Cursor cursor = resolver.query(uri, null, selection, new String[] { cityName }, null); if (cursor.moveToNext()) return Long.parseLong(cursor.getString(cursor.getColumnIndex(WeatherContract.LocationEntry._ID))); else { ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); //resolver.insert(uri, values); return Long.parseLong(resolver.insert(uri, values).getLastPathSegment()); } // return -1; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addOrganizationsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(Organizations.CONTENT_URI, null, "person=" + personId, null, null); try {/*w w w . ja v a2s . c om*/ int companyIndex = c.getColumnIndexOrThrow(Organizations.COMPANY); int titleIndex = c.getColumnIndexOrThrow(Organizations.TITLE); while (c.moveToNext()) { Organization organization = new Organization(); cursorToContactsElement(organization, c, PROVIDER_TYPE_TO_ENTRY_ORGANIZATION); organization.setName(c.getString(companyIndex)); organization.setTitle(c.getString(titleIndex)); entry.addOrganization(organization); } } finally { if (c != null) c.close(); } }
From source file:com.zapto.park.ParkActivity.java
public void doPendingRequests() { EmployeeDB edb = new EmployeeDB(context); // Cursor of pending requests. Cursor cursor = edb.pendingClock(); while (cursor.moveToNext()) { Log.i(LOG_TAG, "Sending pending request."); /*//from w w w.j a v a 2 s. c o m cv.put("totable_license", Globals.LICENSE_KEY); cv.put("totable_id", idValue); cv.put("totable_date", timeStamp); cv.put("totable_inout", checkType == true ? "1" : "1"); */ int _id = cursor.getInt(cursor.getColumnIndex("_id")); String license = cursor.getString(cursor.getColumnIndex("license")); String employee_id = cursor.getString(cursor.getColumnIndex("employee_id")); String date = cursor.getString(cursor.getColumnIndex("date")); String inout = cursor.getString(cursor.getColumnIndex("inout")); int sent = cursor.getInt(cursor.getColumnIndex("sent")); ContentValues cv = new ContentValues(); cv.put("totable_license", license); cv.put("totable_id", employee_id); cv.put("totable_date", date); cv.put("totable_inout", "1"); Log.i(LOG_TAG, "=" + date + "=" + license + "=" + employee_id + "="); //cv.put("totable_inout", inout == 1 ? "1" : "1"); try { Log.i(LOG_TAG, "TRY BLOCK of: doPendingRequest"); String response = SendPost.sendPostRequest("app/clockuser.php", cv); Log.i(LOG_TAG, "TRY BLOCK 2 of: doPendingRequest"); if (response.equals("1") || response.equals("0")) { edb.pendingSent(_id); } } catch (Exception e) { Log.i(LOG_TAG, "Pending resquest failed."); } } edb.close(); }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
private int[] getPorts(long cookieId) { List<Integer> ports = new ArrayList<Integer>(); Cursor cursor = db.query(CookieSQLHelper.PORT_TABLE_NAME, null, CookieSQLHelper.COLUMN_COOKIE_ID + "=?", new String[] { Long.toString(cookieId) }, null, null, null, null); cursor.moveToFirst();/*from w w w . j a v a2s. c om*/ while (!cursor.isAfterLast()) { ports.add(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PORT))); cursor.moveToNext(); } cursor.close(); int[] arrayPorts = new int[ports.size()]; for (int i = 0; i < ports.size(); i++) { arrayPorts[i] = ports.get(i); } return arrayPorts; }
From source file:com.nicolacimmino.expensestracker.tracker.data_sync.ExpenseDataSyncAdapter.java
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w ww . j ava 2s . co m*/ // Get expenses that are not yet synced with the server. Cursor expenses = getContext().getContentResolver().query( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ALL, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC + "=?", new String[] { "0" }, null); while (expenses.moveToNext()) { HttpURLConnection connection = null; try { JSONObject expense = new JSONObject(); expense.put(ExpensesApiContract.Expense.NOTES, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESCRIPTION))); expense.put(ExpensesApiContract.Expense.CURRENCY, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_CURRENCY))); expense.put(ExpensesApiContract.Expense.AMOUNT, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_AMOUNT))); expense.put(ExpensesApiContract.Expense.DESTINATION, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESTINATION))); expense.put(ExpensesApiContract.Expense.SOURCE, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SOURCE))); expense.put(ExpensesApiContract.Expense.TIMESTAMP, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP))); expense.put(ExpensesApiContract.Expense.REPORTER_GCM_REG_ID, GcmRegistration.getRegistration_id()); ExpensesApiNewExpenseRequest request = new ExpensesApiNewExpenseRequest(expense); if (request.performRequest()) { syncResult.stats.numEntries++; ContentValues values = new ContentValues(); values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC, "1"); getContext().getContentResolver().update( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, values, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID + "=?", new String[] { expenses.getString(expenses.getColumnIndex( ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID)) }); } else { syncResult.stats.numIoExceptions++; } } catch (JSONException e) { Log.e(TAG, "Error building json doc: " + e.toString()); syncResult.stats.numIoExceptions++; return; } finally { if (connection != null) { connection.disconnect(); } } } expenses.close(); fetchExpensesFromServer(); Log.i(TAG, "Sync done"); }
From source file:com.appjma.appdeployer.service.Downloader.java
public void syncApps(String token, Uri uri) throws ClientProtocolException, IOException, JSONException, TooManyRecords, WrongHttpResponseCode, UnauthorizedResponseCode { String selection = AppContract.Apps.SYNCED + " = 0"; String[] PROJECTION = new String[] { AppContract.Apps.APP_ID, AppContract.Apps.GUID, AppContract.Apps.NAME, AppContract.Apps.DELETED };/*from ww w . jav a2 s.c o m*/ Cursor cursor = mCr.query(uri, PROJECTION, selection, null, null); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { String id = cursor.getString(0); String guid = cursor.getString(1); String name = cursor.getString(2); boolean deleted = cursor.getInt(3) == 0 ? false : true; if (deleted == true) { checkState(guid != null, "Row could not be marked as deleted if it is not synced"); deleteApp(token, id, guid); } else if (guid == null) { insertApp(token, id, name); } else { updateApp(token, id, guid, name); } } } finally { cursor.close(); } }
From source file:com.openerp.base.res.Res_PartnerSyncHelper.java
public void syncContacts(Context context, Account account) { HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>(); mContentResolver = context.getContentResolver(); int company_id = Integer.parseInt(OpenERPAccountManager.currentUser(context).getCompany_id()); RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build();//from w ww . j av a2s . c o m // Load the local contacts Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(); Cursor cursor = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, SYNC1_PARTNER_ID }, null, null, null); while (cursor.moveToNext()) { SyncEntry entry = new SyncEntry(); entry.partner_id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); localContacts.put(cursor.getString(1), entry); } cursor.close(); try { Res_PartnerDBHelper dbHelper = new Res_PartnerDBHelper(context); HashMap<String, Object> res = dbHelper.search(dbHelper, new String[] { "phone != ? ", "OR", "mobile != ? ", "OR", "email != ?" }, new String[] { "false", "false", "false" }); // checking if records exist? int total = Integer.parseInt(res.get("total").toString()); if (total > 0) { @SuppressWarnings("unchecked") List<HashMap<String, Object>> rows = (List<HashMap<String, Object>>) res.get("records"); for (HashMap<String, Object> row_data : rows) { if (!(row_data.get("company_id").toString()).equalsIgnoreCase("false")) { JSONArray db_company_id = new JSONArray(row_data.get("company_id").toString()); String com_id = db_company_id.getJSONArray(0).getString(0).toString(); if (com_id.equalsIgnoreCase(String.valueOf(company_id))) { String partnerID = row_data.get("id").toString(); String name = (row_data.get("name").toString()).replaceAll("[^\\w\\s]", ""); String mail = row_data.get("email").toString(); String number = row_data.get("phone").toString(); String mobile = row_data.get("mobile").toString(); String website = row_data.get("website").toString(); String street = row_data.get("street").toString(); String street2 = row_data.get("street2").toString(); String city = row_data.get("city").toString(); String zip = row_data.get("zip").toString(); String company = "OpenERP"; String image = row_data.get("image_small").toString(); if (localContacts.get(row_data.get("id").toString()) == null) { addContact(context, account, partnerID, name, mail, number, mobile, website, street, street2, city, zip, company, image); } } } } } } catch (Exception e) { e.printStackTrace(); } }