List of usage examples for android.net Uri toString
public abstract String toString();
From source file:com.dycody.android.idealnote.utils.BitmapHelper.java
public static Uri getThumbnailUri(Context mContext, Attachment mAttachment) { Uri uri = mAttachment.getUri(); String mimeType = StorageHelper.getMimeType(uri.toString()); if (!TextUtils.isEmpty(mimeType)) { String type = mimeType.split("/")[0]; String subtype = mimeType.split("/")[1]; switch (type) { case "image": case "video": // Nothing to do, bitmap will be retrieved from this break; case "audio": uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + com.dycody.android.idealnote.R.raw.play); break; default:// ww w .ja va2 s .c om int drawable = "x-vcard".equals(subtype) ? com.dycody.android.idealnote.R.raw.vcard : com.dycody.android.idealnote.R.raw.files; uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + drawable); break; } } else { uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + com.dycody.android.idealnote.R.raw.files); } return uri; }
From source file:Main.java
/** * Return an {@link InputStream} from the given url or null if failed to retrieve the content * // w w w. j av a2 s. c o m * @param uri * @return */ static InputStream openRemoteInputStream(Uri uri) { java.net.URL finalUrl; try { finalUrl = new java.net.URL(uri.toString()); } catch (MalformedURLException e) { e.printStackTrace(); return null; } HttpURLConnection connection; try { connection = (HttpURLConnection) finalUrl.openConnection(); } catch (IOException e) { e.printStackTrace(); return null; } connection.setInstanceFollowRedirects(false); int code; try { code = connection.getResponseCode(); } catch (IOException e) { e.printStackTrace(); return null; } // permanent redirection if (code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_SEE_OTHER) { String newLocation = connection.getHeaderField("Location"); return openRemoteInputStream(Uri.parse(newLocation)); } try { return (InputStream) finalUrl.getContent(); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:no.norrs.projects.andronary.utils.HttpUtil.java
public static HttpResponse GET(final Uri uri, UsernamePasswordCredentials creds) throws IOException, URISyntaxException { return GET(new URL(uri.toString()), creds); }
From source file:com.kakao.http.HttpRequestTask.java
public static String createBaseURL(final String authority, final String requestPath) { Uri uri = Utility.buildUri(authority, requestPath); return uri.toString(); }
From source file:Main.java
static Uri uriStripQueryParameter(Uri uri, String paramKey) { String queryParam = uri.getQueryParameter(paramKey); if (queryParam == null) { // nothing to strip return uri; } else {// w w w . j a v a2 s. co m String uriString = uri.toString(); String paramString = paramKey + "=" + queryParam; if (uri.getQuery().length() == paramString.length()) { paramString = "?" + paramString; } else if (uriString.length() - paramString.length() == uriString.indexOf(paramString)) { paramString = "&" + paramString; } else { paramString = paramString + "&"; } return Uri.parse(uriString.replace(paramString, "")); } }
From source file:Main.java
@Nullable public static Uri getRingtoneUri(Context context) { Uri ringtoneUri = null;/*from ww w. ja va 2 s . c o m*/ Uri defaultRingtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String prefRingtoneUri = prefs.getString("pref_ringtone_uri", defaultRingtoneUri.toString()); if (prefRingtoneUri.length() > 0) ringtoneUri = Uri.parse(prefRingtoneUri); return ringtoneUri; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java
public static JSONObject json(String groupName, Uri dynUpdateUri) { JSONObject obj = new JSONObject(); try {// ww w .jav a 2 s. c om obj.put(GROUP_NAME, groupName); obj.put(DYN_UPDATE_URI, dynUpdateUri.toString()); } catch (JSONException e) { } return obj; }
From source file:Main.java
/** * Acquires input stream for the image resource identified by uri. * * This is a long-running I/O operation that must run in a background thread. * * @param context/*from w w w . j av a2s . c o m*/ * @param uri * @return * @throws IOException */ public static InputStream getInputStream(Context context, Uri uri) throws IOException { if (uri.getScheme().contentEquals(ContentResolver.SCHEME_CONTENT)) { return context.getContentResolver().openInputStream(uri); } else { return (InputStream) new URL(uri.toString()).getContent(); } }
From source file:ee.ria.DigiDoc.util.FileUtils.java
public static String resolveFileName(Uri uri, ContentResolver contentResolver) { String uriString = uri.toString(); if (isContentUri(uriString)) { try (Cursor cursor = contentResolver.query(uri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); }//from ww w .j av a 2s. c o m } } else if (isFileUri(uriString)) { return new File(uriString).getName(); } return null; }
From source file:Main.java
/** * Generate an input stream reading from an android URI * //from w w w . j a va2s . c o m * @param uri * @return * @throws IOException */ public static InputStream getFromURI(Context context, Uri uri) throws IOException { if (uri.getScheme().equals("content")) return context.getContentResolver().openInputStream(uri); else if (uri.getScheme().equals("file")) { URL url = new URL(uri.toString()); return url.openStream(); } else { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri.toString()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) return entity.getContent(); else throw new IOException("No HTTP response"); // Use the regular java stuff // URL url = new URL(uri.toString()); // return url.openStream(); } }