List of usage examples for android.net Uri getHost
@Nullable public abstract String getHost();
From source file:com.lemi.mario.download.utils.Proxy.java
/** * Return the default proxy host specified by the carrier. * /* www . j a v a2 s . c o m*/ * @return String containing the host name or null if there is no proxy for * this carrier. */ static final public String getDefaultHost() { String host = null; // use reflection to invoke the method try { Class clazz = Class.forName("android.os.SystemProperties"); Method getMethod = clazz.getMethod("get", new Class[] { String.class }); host = (String) getMethod.invoke(clazz, new Object[] { "net.gprs.http-proxy" }); } catch (Exception e) { e.printStackTrace(); } // String host = SystemProperties.get("net.gprs.http-proxy"); if (host != null) { Uri u = Uri.parse(host); host = u.getHost(); return host; } else { return null; } }
From source file:edu.mit.media.funf.util.IOUtil.java
public static boolean isValidUrl(String url) { Log.d(LogUtil.TAG, "Validating url"); boolean isValidUrl = false; if (url != null && !url.trim().equals("")) { try {/*from w w w .j ava 2 s. co m*/ Uri test = Uri.parse(url); isValidUrl = test.getScheme() != null && test.getScheme().startsWith("http") && test.getHost() != null && !test.getHost().trim().equals(""); } catch (Exception e) { Log.d(LogUtil.TAG, "Not valid", e); } } Log.d(LogUtil.TAG, "Valid url? " + isValidUrl); return isValidUrl; }
From source file:com.appnexus.opensdk.ANJAMImplementation.java
static void handleUrl(AdWebView webView, String url) { Uri uri = Uri.parse(url); String call = uri.getHost(); if (CALL_MAYDEEPLINK.equals(call)) { callMayDeepLink(webView, uri);//from w ww . j a v a 2 s.c om } else if (CALL_DEEPLINK.equals(call)) { if (webView.getUserInteraction()) { callDeepLink(webView, uri); } else { Clog.w(Clog.jsLogTag, Clog.getString(R.string.no_user_interaction, url)); } } else if (CALL_EXTERNALBROWSER.equals(call)) { if (webView.getUserInteraction()) { callExternalBrowser(webView, uri); } else { Clog.w(Clog.jsLogTag, Clog.getString(R.string.no_user_interaction, url)); } } else if (CALL_INTERNALBROWSER.equals(call)) { if (webView.getUserInteraction()) { callInternalBrowser(webView, uri); } else { Clog.w(Clog.jsLogTag, Clog.getString(R.string.no_user_interaction, url)); } } else if (CALL_RECORDEVENT.equals(call)) { callRecordEvent(webView, uri); } else if (CALL_DISPATCHAPPEVENT.equals(call)) { callDispatchAppEvent(webView, uri); } else if (CALL_GETDEVICEID.equals(call)) { callGetDeviceID(webView, uri); } else { Clog.w(Clog.baseLogTag, "ANJAM called with unsupported function: " + call); } }
From source file:com.oakesville.mythling.util.MediaStreamProxy.java
public static URL getNetUrl(Uri mediaUri) throws MalformedURLException { String netUrl = mediaUri.getScheme() + "://" + mediaUri.getHost() + ":" + mediaUri.getPort(); netUrl += mediaUri.getPath();// www. j av a2 s. c o m if (mediaUri.getQuery() != null) netUrl += "?" + mediaUri.getEncodedQuery(); return new URL(netUrl); }
From source file:com.entertailion.android.launcher.spotlight.ProcessSpotlight.java
/** * Process the spotlight JSON data/* ww w. ja v a 2 s. com*/ * * @param jsonFeed * @return * @throws JSONException */ public static List<SpotlightInfo> process(Context context, String jsonFeed) throws JSONException { JSONObject jsonObj = new JSONObject(jsonFeed); List<SpotlightInfo> result = null; if (null != jsonObj) { JSONArray models = (JSONArray) jsonObj.get("models"); if (null != models && models.length() > 0) { result = new ArrayList<SpotlightInfo>(); int position = 0; for (int i = 0; i < models.length(); i++) { JSONObject model = (JSONObject) models.get(i); String title = model.getString("title"); String url = model.getString("url"); String logo = model.getString("hdpiLogo"); String icon = null; if (null == SpotlightInfo.spotlightIconMap.get(title.toLowerCase())) { // icon file path try { icon = "spotlight_" + sanitizeName(title) + ".png"; File file = context.getFileStreamPath(icon); if (!file.exists()) { Uri uri = Uri.parse(url); String alternateLogo = Utils.getWebSiteIcon(context, uri.getScheme() + "://" + uri.getHost()); if (alternateLogo != null && alternateLogo.trim().length() > 0) { icon = alternateLogo; } else { // create a file-based icon from original // 360x203 Bitmap bitmap = Utils.getBitmapFromURL(logo); if (bitmap != null) { bitmap = Utils.crop(bitmap, 30, 30); Utils.saveToFile(context, bitmap, 100, 100, icon); bitmap.recycle(); bitmap = null; } else { icon = null; } } } } catch (Exception e) { Log.e(LOG_TAG, "create spotlight icon", e); } } Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); result.add(new SpotlightInfo(position++, title, browserIntent, logo, icon)); } } } return result; }
From source file:id.nci.stm_9.FileHelper.java
/** * Get a file path from a Uri./*from ww w . j av a2s. co m*/ * * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/ * afilechooser/utils/FileUtils.java * * @param context * @param uri * @return * * @author paulburke */ public static String getPath(Context context, Uri uri) { Log.d("Stm-9" + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:org.sufficientlysecure.keychain.helper.FileHelper.java
/** * Get a file path from a Uri.//from w w w.java 2 s . co m * <p/> * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/ * afilechooser/utils/FileUtils.java * * @param context * @param uri * @return * @author paulburke */ public static String getPath(Context context, Uri uri) { Log.d(Constants.TAG + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndexOrThrow("_data"); return cursor.getString(columnIndex); } } catch (Exception e) { // Eat it } finally { if (cursor != null) { cursor.close(); } } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:org.thialfihar.android.apg.helper.FileHelper.java
/** * Get a file path from a Uri./*w w w.ja v a 2 s . co m*/ * * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/ * afilechooser/utils/FileUtils.java * * @param context * @param uri * @return * * @author paulburke */ public static String getPath(Context context, Uri uri) { Log.d(Constants.TAG + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int columnIndex = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(columnIndex); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:bolts.MeasurementEvent.java
private static Bundle getApplinkLogData(Context context, String eventName, Bundle appLinkData, Intent applinkIntent) {/*from w ww.j av a2s .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
/** * Get a file path from a Uri.// w w w .j av a 2s .c o m * * @param context * @param uri * @return * @throws URISyntaxException * * @author paulburke */ public static String getPath(Context context, Uri uri) throws URISyntaxException { if (DEBUG) Log.d(TAG + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }