List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.codebutler.farebot.key.CardKeys.java
public static CardKeys forTagId(byte[] tagId) throws Exception { String tagIdString = Utils.getHexString(tagId); FareBotApplication app = FareBotApplication.getInstance(); Cursor cursor = app.getContentResolver() .query(Uri.withAppendedPath(CardKeyProvider.CONTENT_URI, tagIdString), null, null, null, null); if (cursor.moveToFirst()) { return CardKeys.fromCursor(cursor); } else {/*from w ww . jav a2 s .c o m*/ return null; } }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshTracks(long albumId) { try {/*w w w . ja v a2s.c o m*/ ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(1); JSONArray json = ApiHelper.callApiForArray("tracks", null, new String[] { "album" }, new String[] { Long.toString(albumId) }); operations.ensureCapacity(operations.size() + json.length() + 1); operations.add(ContentProviderOperation .newDelete(Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS_ALBUM, Long.toString(albumId))) .build()); for (int j = 0; j < json.length(); ++j) { JSONObject o = json.getJSONObject(j); ContentValues values = new ContentValues(); values.put(TrackEntry.SHORT_ID, o.getInt("id")); values.put(TrackEntry.SHORT_ARTIST_ID, o.getInt("artist_id")); values.put(TrackEntry.SHORT_ALBUM_ID, o.getInt("album_id")); values.put(TrackEntry.SHORT_TITLE, o.getString("title")); if (!o.isNull("tracknumber")) values.put(TrackEntry.SHORT_TRACKNUMBER, o.getInt("tracknumber")); if (!o.isNull("discnumber")) values.put(TrackEntry.SHORT_DISCNUMBER, o.getInt("discnumber")); values.put(TrackEntry.SHORT_LABEL, o.getString("label")); values.put(TrackEntry.SHORT_CATALOGNUMBER, o.getString("catalognumber")); values.put(TrackEntry.SHORT_LENGTH, o.getInt("length")); values.put(TrackEntry.SHORT_DATE, o.getString("date")); operations.add(ContentProviderOperation .newDelete( Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS, Integer.toString(o.getInt("id")))) .build()); operations.add( ContentProviderOperation.newInsert(MuckeboxProvider.URI_TRACKS).withValues(values).build()); } Log.d(LOG_TAG, "Got " + json.length() + " Tracks"); Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_tracks; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_tracks; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_tracks; } return null; }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Gets the name of a contact from the Android contacts provider, given a phone number. * * @param applicationContext The application context. * @param phoneNumber The phone number of the contact. * @return the name of the contact./*from ww w .ja v a 2 s .co m*/ */ public static String getContactName(Context applicationContext, String phoneNumber) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = applicationContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToFirst()) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); cursor.close(); return name; } else { cursor.close(); return null; } }
From source file:org.trakhound.www.trakhound.device_list.DeviceStatus.java
public static DeviceStatus[] get(UserConfiguration userConfig) { if (userConfig != null) { try {//from w ww .j a v a2s. co m DateTime now = DateTime.now(); DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0); DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + URLEncoder.encode(userConfig.sessionToken, "UTF-8") + "&sender_id=" + URLEncoder.encode(UserManagement.getSenderId(), "UTF-8") + "&from=" + fromStr + "&to=" + toStr + "&command=0101"; // Get Status and Oee tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { ArrayList<DeviceStatus> devicesStatuses = new ArrayList<>(); try { JSONArray a = new JSONArray(response); for (int i = 0; i < a.length(); i++) { JSONObject obj = a.getJSONObject(i); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); devicesStatuses.add(deviceStatus); } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } DeviceStatus[] deviceStatusArray = new DeviceStatus[devicesStatuses.size()]; return devicesStatuses.toArray(deviceStatusArray); } } catch (UnsupportedEncodingException ex) { Log.d("Exception", ex.getMessage()); } } return null; }
From source file:org.trakhound.www.trakhound.device_details.DeviceStatus.java
public static DeviceStatus get(UserConfiguration userConfig, String uniqueId) { if (userConfig != null) { DateTime now = DateTime.now();/*from ww w. j av a2s . co m*/ DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0); DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + userConfig.sessionToken + "&sender_id=" + UserManagement.getSenderId() + "&devices=[{\"unique_id\":\"" + uniqueId + "\"}]" + "&from=" + fromStr + "&to=" + toStr + "&command=" + "01111"; // Get Status, Controller, Oee, and Timers tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { try { JSONArray a = new JSONArray(response); if (a.length() > 0) { JSONObject obj = a.getJSONObject(0); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.controllerInfo = ControllerInfo.parse(obj.getJSONObject("controller")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); deviceStatus.timersInfo = TimersInfo.parse(obj.getJSONObject("timers")); return deviceStatus; } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } } } return null; }
From source file:com.bottlerocketstudios.groundcontrolsample.core.controller.ProductApi.java
private static String createFullUrl(Configuration configuration, String appendedPath) { return Uri.withAppendedPath(configuration.getBaseUrl(), appendedPath).toString(); }
From source file:Main.java
/** * Finding contact name by telephone number. * * @param context Context/*from w ww .j a va 2 s. c om*/ * @param number Telephone number * @return Contact display name */ public static String getContactName(Context context, String number) { Log.d(TAG, "Searching contact with number: " + number); /* define the columns I want the query to return */ String[] projection = new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }; /* encode the phone number and build the filter URI */ Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); /* query time */ Log.d(TAG, "Sending query"); Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null); String name = null; if (cursor.moveToFirst()) { /* Get values from contacts database: */ name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); Log.d(TAG, "Contact found for number: " + number + ". The name is: " + name); } else { Log.d(TAG, "Contact not found for number: " + number); } return name; }
From source file:edu.mit.mobile.android.locast.data.Itinerary.java
public static Uri getCastsUri(Uri itinerary) { if (ContentUris.parseId(itinerary) == -1) { throw new IllegalArgumentException(itinerary + " does not appear to be an itinerary item URI"); }/* w w w . jav a 2 s. c o m*/ return Uri.withAppendedPath(itinerary, Cast.PATH); }
From source file:com.microsoft.graph.connect.AuthenticationManager.java
private AuthenticationManager() { Uri authorityUrl = Uri.parse(Constants.AUTHORITY_URL); Uri authorizationEndpoint = Uri.withAppendedPath(authorityUrl, Constants.AUTHORIZATION_ENDPOINT); Uri tokenEndpoint = Uri.withAppendedPath(authorityUrl, Constants.TOKEN_ENDPOINT); mConfig = new AuthorizationServiceConfiguration(authorizationEndpoint, tokenEndpoint, null); List<String> scopes = new ArrayList<>(Arrays.asList(Constants.SCOPES.split(" "))); mAuthorizationRequest = new AuthorizationRequest.Builder(mConfig, Constants.CLIENT_ID, ResponseTypeValues.CODE, Uri.parse(Constants.REDIRECT_URI)).setScopes(scopes).build(); }
From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java
private static String getNameFromPhoneNumber(Context context, String phone) { Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, phone), new String[] { Contacts.Phones.NAME }, null, null, null); if (cursor != null) { try {/*from w w w.j a v a 2 s . co m*/ if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); Log.e("PUSH_CONTACTS", "Pushed name: " + name); return name; } } finally { cursor.close(); } } return null; }