List of usage examples for android.content ContentProviderClient query
public @Nullable Cursor query(@NonNull Uri url, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) throws RemoteException
From source file:at.bitfire.davdroid.resource.LocalCalendar.java
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient) throws RemoteException { @Cleanup// w w w . ja v a2s .c om Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME }, Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null); LinkedList<LocalCalendar> calendars = new LinkedList<>(); while (cursor != null && cursor.moveToNext()) calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1))); return calendars.toArray(new LocalCalendar[calendars.size()]); }
From source file:org.exfio.csyncdroid.resource.LocalCalendar.java
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient, AccountSettings accountSettings) throws RemoteException { @Cleanup/* w w w .ja va 2 s. c o m*/ Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME, COLLECTION_COLUMN_CTAG, Calendars.CALENDAR_TIME_ZONE }, Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null); LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>(); while (cursor != null && cursor.moveToNext()) calendars.add(new LocalCalendar(account, providerClient, accountSettings, cursor.getInt(0), cursor.getString(3))); return calendars.toArray(new LocalCalendar[0]); }
From source file:com.taxicop.sync.SyncAdapter.java
public int count(ContentProviderClient provider) { try {// w ww. j a va2 s . co m Cursor c = provider.query(PlateContentProvider.URI_REPORT, null, null, null, null); int ret = c.getCount(); c.close(); return ret; } catch (Exception e) { // TODO Auto-generated catch block Log.e(TAG, "" + e.getMessage()); } return 0; }
From source file:com.android.example.leanback.fastlane.RecommendationsService.java
@Override protected void onHandleIntent(Intent intent) { ContentProviderClient client = getContentResolver() .acquireContentProviderClient(VideoItemContract.VideoItem.buildDirUri()); try {//from w w w . j a v a 2 s.c om Cursor cursor = client.query(VideoItemContract.VideoItem.buildDirUri(), VideoDataManager.PROJECTION, null, null, VideoItemContract.VideoItem.DEFAULT_SORT); VideoDataManager.VideoItemMapper mapper = new VideoDataManager.VideoItemMapper(); mapper.bindColumns(cursor); NotificationManager mNotificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); Log.d(TAG, mNotificationManager == null ? "It's null" : mNotificationManager.toString()); int count = 1; while (cursor.moveToNext() && count <= MAX_RECOMMENDATIONS) { Video video = mapper.bind(cursor); PendingIntent pendingIntent = buildPendingIntent(video); Bundle extras = new Bundle(); extras.putString(EXTRA_BACKGROUND_IMAGE_URL, video.getThumbUrl()); Bitmap image = Picasso.with(getApplicationContext()).load(video.getThumbUrl()) .resize(VideoDetailsFragment.dpToPx(DETAIL_THUMB_WIDTH, getApplicationContext()), VideoDetailsFragment.dpToPx(DETAIL_THUMB_HEIGHT, getApplicationContext())) .get(); Notification notification = new NotificationCompat.BigPictureStyle( new NotificationCompat.Builder(getApplicationContext()).setContentTitle(video.getTitle()) .setContentText(video.getDescription()).setPriority(4).setLocalOnly(true) .setOngoing(true) .setColor(getApplicationContext().getResources().getColor(R.color.primary)) // .setCategory(Notification.CATEGORY_RECOMMENDATION) .setCategory("recommendation").setLargeIcon(image) .setSmallIcon(R.drawable.ic_stat_f).setContentIntent(pendingIntent) .setExtras(extras)).build(); mNotificationManager.notify(count, notification); count++; } cursor.close(); } catch (RemoteException re) { Log.e(TAG, "Cannot query VideoItems", re); } catch (IOException re) { Log.e(TAG, "Cannot download thumbnail", re); } finally { client.release(); } }
From source file:com.taxicop.sync.SyncAdapter.java
public int queryLastId(ContentProviderClient provider) { Cursor c = null;/*from w w w . j a v a 2s . co m*/ int id = 0; try { c = provider.query(PlateContentProvider.URI_USERS, null, null, null, null); if (c.moveToFirst()) id = c.getInt(c.getColumnIndex(Fields.ITH)); } catch (Exception e) { Log.e(TAG, "lastId= " + e.getMessage()); } c.close(); return id; }
From source file:com.taxicop.sync.SyncAdapter.java
public String queryUser(ContentProviderClient provider) { Cursor c = null;//w w w. j a v a 2 s . c o m String usr = null; try { c = provider.query(PlateContentProvider.URI_USERS, null, null, null, null); if (c.moveToFirst()) { usr = c.getString(c.getColumnIndex(Fields.ID_USR)); } } catch (Exception e) { Log.e(TAG, "queryuser= " + e.getMessage()); } c.close(); return usr; }
From source file:fr.free.nrw.commons.contributions.ContributionDao.java
Cursor loadAllContributions() { ContentProviderClient db = clientProvider.get(); try {//from w w w.ja va 2 s. c om return db.query(BASE_URI, ALL_FIELDS, "", null, CONTRIBUTION_SORT); } catch (RemoteException e) { return null; } finally { db.release(); } }
From source file:com.taxicop.sync.SyncAdapter.java
public ArrayList<Complaint> query(ContentProviderClient provider, int FROM) { ArrayList<Complaint> reports = new ArrayList<Complaint>(); try {//from ww w.j a va2 s. c o m Cursor c = provider.query(PlateContentProvider.URI_REPORT, null, Fields.ID_KEY + " > " + FROM + "", null, null); if (c.moveToFirst()) { do { float rank = c.getFloat(c.getColumnIndex(Fields.RANKING)); String plate = "" + (c.getString(c.getColumnIndex(Fields.CAR_PLATE))); String desc = "" + (c.getString(c.getColumnIndex(Fields.DESCRIPTION))); String date = "" + (c.getString(c.getColumnIndex(Fields.DATE_REPORT))); Log.d(TAG, "plate=" + plate); reports.add(new Complaint(rank, plate, desc, USER, date)); } while (c.moveToNext()); } c.close(); } catch (Exception e) { Log.e(TAG, "query= " + e.getMessage()); } return reports; }
From source file:com.snu.msl.sensys.SyncAdapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient, SyncResult syncResult) {/*from w ww .j a v a2 s. c o m*/ Log.d("UPUP", "Reached here"); try { Cursor cursor = contentProviderClient.query( Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null); cursor.moveToFirst(); StringBuilder res = new StringBuilder(); while (!cursor.isAfterLast()) { String timestamp = cursor.getString(cursor.getColumnIndex("timestamp")); String firstTime = cursor.getString(cursor.getColumnIndex("firsttime")); String gpsLatitude = cursor.getString(cursor.getColumnIndex("gpslatitude")); String gpsLongitude = cursor.getString(cursor.getColumnIndex("gpslongitude")); String sensordroneMAC = cursor.getString(cursor.getColumnIndex("sensordronemac")); String sensordroneTemperature = cursor.getString(cursor.getColumnIndex("sensordronetemperature")); String sensordroneHumidity = cursor.getString(cursor.getColumnIndex("sensordronehumidity")); String sensordronePressure = cursor.getString(cursor.getColumnIndex("sensordronepressure")); String sensordroneIRTemperature = cursor .getString(cursor.getColumnIndex("sensordroneirtemperature")); String sensordroneIlluminance = cursor.getString(cursor.getColumnIndex("sensordroneilluminance")); String sensordronePrecisionGas = cursor.getString(cursor.getColumnIndex("sensordroneprecisiongas")); String sensordroneCapacitance = cursor.getString(cursor.getColumnIndex("sensordronecapacitance")); String sensordroneExternalVoltage = cursor .getString(cursor.getColumnIndex("sensordroneexternalvoltage")); String sensordroneBatteryVoltage = cursor .getString(cursor.getColumnIndex("sensordronebatteryvoltage")); String sensordroneOxidizingGas = cursor.getString(cursor.getColumnIndex("sensordroneoxidizinggas")); String sensordroneReducingGas = cursor.getString(cursor.getColumnIndex("sensordronereducinggas")); String gpsAltitude = cursor.getString(cursor.getColumnIndex("gpsaltitude")); String sensordroneCO2 = cursor.getString(cursor.getColumnIndex("sensordroneco2")); String responseString = ""; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://mobisense.webapps.snu.edu.in/ITRAWebsite/upload/sensordroneupload.php"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("user", account.name)); nameValuePairs.add(new BasicNameValuePair("timestamp", timestamp)); nameValuePairs.add(new BasicNameValuePair("firsttime", firstTime)); nameValuePairs.add(new BasicNameValuePair("gpslatitude", gpsLatitude)); nameValuePairs.add(new BasicNameValuePair("gpslongitude", gpsLongitude)); nameValuePairs.add(new BasicNameValuePair("sensordronemac", sensordroneMAC)); nameValuePairs.add(new BasicNameValuePair("sensordronetemperature", sensordroneTemperature)); nameValuePairs.add(new BasicNameValuePair("sensordronehumidity", sensordroneHumidity)); nameValuePairs.add(new BasicNameValuePair("sensordronepressure", sensordronePressure)); nameValuePairs .add(new BasicNameValuePair("sensordroneirtemperature", sensordroneIRTemperature)); nameValuePairs.add(new BasicNameValuePair("sensordroneilluminance", sensordroneIlluminance)); nameValuePairs.add(new BasicNameValuePair("sensordroneprecisiongas", sensordronePrecisionGas)); nameValuePairs.add(new BasicNameValuePair("sensordronecapacitance", sensordroneCapacitance)); nameValuePairs .add(new BasicNameValuePair("sensordroneexternalvoltage", sensordroneExternalVoltage)); nameValuePairs .add(new BasicNameValuePair("sensordronebatteryvoltage", sensordroneBatteryVoltage)); nameValuePairs.add(new BasicNameValuePair("sensordroneoxidizinggas", sensordroneOxidizingGas)); nameValuePairs.add(new BasicNameValuePair("sensordronereducinggas", sensordroneReducingGas)); nameValuePairs.add(new BasicNameValuePair("sensordroneco2", sensordroneCO2)); nameValuePairs.add(new BasicNameValuePair("gpsaltitude", gpsAltitude)); Log.d("TAG", sensordroneOxidizingGas + ", " + sensordroneReducingGas + ", " + sensordroneTemperature); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, "UTF-8"); Log.d("TAGFFFF", responseString); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } if (responseString.equalsIgnoreCase("Success")) contentProviderClient.delete(Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), "timestamp=?", new String[] { timestamp }); cursor = contentProviderClient.query( Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null); cursor.moveToFirst(); } } catch (RemoteException e) { syncResult.hasHardError(); e.printStackTrace(); } }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null;//from w w w . j ava2 s.co m try { cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }