List of usage examples for android.net Uri toString
public abstract String toString();
From source file:Main.java
/** * Return the MIME type from the URI/*w w w. j a va2 s . c om*/ * @param context Context * @param uri URI * @return Return the MIME type */ public static String getMimetypeFromUri(Context context, Uri uri) { String contentType = context.getContentResolver().getType(uri); if (TextUtils.isEmpty(contentType)) { final MimeTypeMap type_map = MimeTypeMap.getSingleton(); // Get the extension from the path String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); extension = extension.toLowerCase(); if (extension.contains(".")) { extension = extension.substring(extension.lastIndexOf(".")); } contentType = type_map.getMimeTypeFromExtension(extension); } return contentType; }
From source file:bolts.MeasurementEvent.java
private static Bundle getApplinkLogData(Context context, String eventName, Bundle appLinkData, Intent applinkIntent) {//from w ww . j av a 2 s . co m Bundle logData = new Bundle(); ComponentName resolvedActivity = applinkIntent.resolveActivity(context.getPackageManager()); if (resolvedActivity != null) { logData.putString("class", resolvedActivity.getShortClassName()); } if (APP_LINK_NAVIGATE_OUT_EVENT_NAME.equals(eventName)) { if (resolvedActivity != null) { logData.putString("package", resolvedActivity.getPackageName()); } if (applinkIntent.getData() != null) { logData.putString("outputURL", applinkIntent.getData().toString()); } if (applinkIntent.getScheme() != null) { logData.putString("outputURLScheme", applinkIntent.getScheme()); } } else if (APP_LINK_NAVIGATE_IN_EVENT_NAME.equals(eventName)) { if (applinkIntent.getData() != null) { logData.putString("inputURL", applinkIntent.getData().toString()); } if (applinkIntent.getScheme() != null) { logData.putString("inputURLScheme", applinkIntent.getScheme()); } } for (String key : appLinkData.keySet()) { Object o = appLinkData.get(key); if (o instanceof Bundle) { for (String subKey : ((Bundle) o).keySet()) { String logValue = objectToJSONString(((Bundle) o).get(subKey)); if (key.equals("referer_app_link")) { if (subKey.equalsIgnoreCase("url")) { logData.putString("refererURL", logValue); continue; } else if (subKey.equalsIgnoreCase("app_name")) { logData.putString("refererAppName", logValue); continue; } else if (subKey.equalsIgnoreCase("package")) { logData.putString("sourceApplication", logValue); continue; } } logData.putString(key + "/" + subKey, logValue); } } else { String logValue = objectToJSONString(o); if (key.equals("target_url")) { Uri targetURI = Uri.parse(logValue); logData.putString("targetURL", targetURI.toString()); logData.putString("targetURLHost", targetURI.getHost()); continue; } logData.putString(key, logValue); } } return logData; }
From source file:Main.java
@Nullable private static InputStream getStreamFromUri(Uri selectedImageURI, Context theContext) throws IOException { switch (selectedImageURI.getScheme()) { case "content": return theContext.getContentResolver().openInputStream(selectedImageURI); case "file": return new FileInputStream(new File(URI.create(selectedImageURI.toString()))); case "http": // Fall through case "https": final URL url = new URL(selectedImageURI.toString()); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true);/* ww w .j a va2s .c o m*/ connection.connect(); return connection.getInputStream(); default: Log.w(TAG, "getStreamFromUri(): unsupported Uri scheme: " + selectedImageURI.getScheme()); return null; } }
From source file:bolts.MeasurementEvent.java
/** * Broadcast Bolts measurement event.//from ww w. j a v a 2 s . c o m * Bolts raises events to the application with this method by sending * {@link #MEASUREMENT_EVENT_NOTIFICATION_NAME} broadcast. * * @param context the context of activity or application who is going to send the event. required. * @param name the event name that is going to be sent. required. * @param intent the intent that carries the logging data in its extra bundle and data url. optional. * @param extraLoggingData other logging data to be sent in events argument. optional. * */ static void sendBroadcastEvent(Context context, String name, Intent intent, Map<String, String> extraLoggingData) { Bundle logData = new Bundle(); if (intent != null) { Bundle applinkData = AppLinks.getAppLinkData(intent); if (applinkData != null) { logData = getApplinkLogData(context, name, applinkData, intent); } else { Uri intentUri = intent.getData(); if (intentUri != null) { logData.putString("intentData", intentUri.toString()); } Bundle intentExtras = intent.getExtras(); if (intentExtras != null) { for (String key : intentExtras.keySet()) { Object o = intentExtras.get(key); String logValue = objectToJSONString(o); logData.putString(key, logValue); } } } } if (extraLoggingData != null) { for (String key : extraLoggingData.keySet()) { logData.putString(key, extraLoggingData.get(key)); } } MeasurementEvent event = new MeasurementEvent(context, name, logData); event.sendBroadcast(); }
From source file:Main.java
/** * Consolidates the file path determination functionality of the various * media prompts. Beginning with KitKat, the responses use a different * mechanism and needs a lot of special handling. * * @param ctxt/*w ww . java2s . c om*/ * @param uri * @param pathKey * @return */ @SuppressLint("NewApi") public static String getPathFromUri(Context ctxt, Uri uri, String pathKey) { if (Build.VERSION.SDK_INT >= 19) { return getPath(ctxt, uri); } else { if (uri.toString().startsWith("file")) { return uri.toString().substring(7); } else { String[] projection = { pathKey }; Cursor c = null; try { c = ctxt.getContentResolver().query(uri, projection, null, null, null); int column_index = c.getColumnIndexOrThrow(pathKey); String path = null; if (c.getCount() > 0) { c.moveToFirst(); path = c.getString(column_index); } return path; } finally { if (c != null) { c.close(); } } } } }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String deleteSensor(Uri uri, Sensor sensor) throws RequestErrorException { URI target;/*from ww w . j av a2 s.c om*/ try { target = new URI(uri.toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestErrorException(e.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpDelete request = new HttpDelete(target); request.setHeader("Content-type", "application/json"); String response = null; try { response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } return response; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String putData(Uri uri, String data) throws RequestErrorException { URI target;//from www. j a v a 2 s . co m try { target = new URI(uri.toString() + DISPATCHER_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPut request = new HttpPut(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(data); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (response.trim().length() > 2) { throw new RequestErrorException("Sensor not registred: " + response); } return response; }
From source file:com.android.dialer.lookup.dastelefonbuch.TelefonbuchApi.java
public static ContactInfo reverseLookup(Context context, String number) throws IOException { Uri uri = Uri.parse(REVERSE_LOOKUP_URL).buildUpon().appendQueryParameter("kw", number).build(); // Cut out everything we're not interested in (scripts etc.) to // speed up the subsequent matching. String output = LookupUtils.firstRegexResult(LookupUtils.httpGet(new HttpGet(uri.toString())), ": Treffer(.*)Ende Treffer", true); String name = parseValue(output, NAME_REGEX, true, false); if (name == null) { return null; }// w w w .jav a 2 s. c o m String phoneNumber = parseValue(output, NUMBER_REGEX, false, true); String address = parseValue(output, ADDRESS_REGEX, true, true); ContactInfo info = new ContactInfo(); info.name = name; info.address = address; info.formattedNumber = phoneNumber != null ? phoneNumber : number; info.website = uri.toString(); return info; }
From source file:info.guardianproject.netcipher.NetCipher.java
/** * Get a {@link HttpURLConnection} from a {@link Uri}. If it is an * {@code https://} link, then this will use the best TLS configuration * available on the device./* w w w . ja v a 2 s . c o m*/ * * @param uri * @return the {@code uri} in an instance of {@link HttpURLConnection} * @throws IOException * @throws IllegalArgumentException if the proxy or TLS setup is incorrect */ public static HttpURLConnection getHttpURLConnection(Uri uri) throws IOException { return getHttpURLConnection(uri.toString()); }
From source file:info.guardianproject.netcipher.NetCipher.java
/** * Get a {@link HttpsURLConnection} from a {@link Uri} using the best TLS * configuration available on the device. * * @param uri//www .ja v a 2 s .c om * @return the {@code uri} in an instance of {@link HttpsURLConnection} * @throws IOException * @throws IllegalArgumentException if the proxy or TLS setup is incorrect, * or if an HTTP URL is given that does not support HTTPS */ public static HttpsURLConnection getHttpsURLConnection(Uri uri) throws IOException { return getHttpsURLConnection(uri.toString()); }