Example usage for android.net Uri getHost

List of usage examples for android.net Uri getHost

Introduction

In this page you can find the example usage for android.net Uri getHost.

Prototype

@Nullable
public abstract String getHost();

Source Link

Document

Gets the encoded host from the authority for this URI.

Usage

From source file:Main.java

static void assertUriSafe(@Nullable Uri uri) {
    if (uri == null || TextUtils.isEmpty(uri.getScheme()) || TextUtils.isEmpty(uri.getHost())) {
        throw new RuntimeException("Unsafe uri provided");
    }//  ww  w.j a  va 2 s.  co  m
}

From source file:Main.java

@Nullable
public static Uri safeUri(@NonNull String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    }/*from www. ja  v  a  2  s .co m*/

    Uri uri = Uri.parse(url);

    if (TextUtils.isEmpty(uri.getScheme()) || TextUtils.isEmpty(uri.getHost())) {
        return null;
    }

    return uri;
}

From source file:com.achep.acdisplay.receiver.LocalReceiverActivity.java

static String extractHost(Intent intent) {
    Uri data = intent.getData();
    return data != null ? data.getHost() : null;
}

From source file:Main.java

public static String makeSpecUrl(String inBaseUrl) {
    Uri path = Uri.parse(inBaseUrl);
    String port = path.getPort() != -1 ? ":" + String.valueOf(path.getPort()) : "";
    return path.getScheme() + "://" + path.getHost() + port + path.getPath();
}

From source file:org.fdroid.fdroid.installer.ApkCache.java

/**
 * Get the full path for where an APK URL will be downloaded into.
 *///from  w  w w.j a v  a 2  s.  c  o  m
public static SanitizedFile getApkDownloadPath(Context context, Uri uri) {
    File dir = new File(getApkCacheDir(context), uri.getHost() + "-" + uri.getPort());
    if (!dir.exists()) {
        dir.mkdirs();
    }
    return new SanitizedFile(dir, uri.getLastPathSegment());
}

From source file:com.appnexus.opensdk.PBImplementation.java

static void handleUrl(AdWebView adWebView, String url) {
    if ((adWebView == null) || (adWebView.getContext() == null)) {
        return;//  ww w . ja v  a  2s.c  o  m
    }
    Context context = adWebView.getContext();
    Uri uri = Uri.parse(url);
    String host = uri.getHost();
    if (HOST_WEB.equals(host)) {
        if (adWebView.getUserInteraction()) {
            launchApp(context);
        }
    } else if (HOST_APP.equals(host)) {
        String auctionInfo = uri.getQueryParameter(KEY_AUCTIONINFO);
        saveAuctionInfo(auctionInfo);

    } else if (HOST_CAPTURE.equals(host)) {
        String auctionID = uri.getQueryParameter(KEY_AUCTIONID);

        String auctionInfo = buffer.get(auctionID);
        if (auctionInfo == null) {
            return;
        }
        captureImage(context, adWebView, auctionInfo);
    }
}

From source file:ch.lipsch.deshortener.Deshortener.java

private static boolean checkForPreview(Uri uri) {
    return PREVIEW_HOSTS.contains(uri.getHost());
}

From source file:com.nttec.everychan.chans.WakabaFactory.java

private static ChanModule createChanModule(SharedPreferences preferences, Resources resources, String url,
        final DateFormat df) {
    Uri uri = Uri.parse(url);
    final String name = uri.getHost();
    final boolean https = uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("https");
    return new AbstractWakabaModule(preferences, resources) {
        private final List<DateFormat> dateFormats;
        {/*from ww  w  .j a v  a  2  s  . c  o  m*/
            dateFormats = Arrays
                    .asList(new DateFormat[] { df, new SimpleDateFormat("yy/MM/dd(EEE)HH:mm", Locale.US),
                            new SimpleDateFormat("EEE dd MMM yyyy HH:mm:ss", Locale.US),
                            new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.US) {
                                private static final long serialVersionUID = 1L;

                                public Date parse(String string) throws ParseException {
                                    return super.parse(string.replaceAll(" ?\\(.*?\\)", ""));
                                }
                            }, new SimpleDateFormat("EEE yy/MM/dd HH:mm", Locale.US),
                            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US) });
        }

        @Override
        public String getDisplayingName() {
            return name;
        }

        @Override
        public String getChanName() {
            return name;
        }

        @Override
        public Drawable getChanFavicon() {
            return ResourcesCompat.getDrawable(resources, R.drawable.favicon_cirno, null);
        }

        @Override
        protected String getUsingDomain() {
            return name;
        }

        @Override
        protected SimpleBoardModel[] getBoardsList() {
            return new SimpleBoardModel[0];
        }

        @Override
        protected boolean canHttps() {
            return true;
        }

        protected boolean useHttpsDefaultValue() {
            return https;
        };

        @Override
        protected boolean canCloudflare() {
            return true;
        }

        @SuppressWarnings("serial")
        @SuppressLint("SimpleDateFormat")
        @Override
        protected WakabaReader getWakabaReader(InputStream stream, UrlPageModel urlModel) {
            return new WakabaReader(stream, new SimpleDateFormat() { // universal date format
                @Override
                public Date parse(String string) throws ParseException {
                    for (DateFormat df : dateFormats) {
                        try {
                            return df.parse(string);
                        } catch (Exception e) {
                        }
                    }
                    Logger.d(TAG, "couldn't parse: '" + string + "'");
                    return new Date(0);
                }
            });
        }
    };
}

From source file:Main.java

public static String buildAccountName(Uri serverBaseUrl, String username) {
    if (serverBaseUrl.getScheme() == null) {
        serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
    }// ww w  .java2s .  com
    String accountName = username + "@" + serverBaseUrl.getHost();
    if (serverBaseUrl.getPort() >= 0) {
        accountName += ":" + serverBaseUrl.getPort();
    }
    return accountName;
}

From source file:Main.java

public static String buildAccountNameOld(Uri serverBaseUrl, String username) {
    if (serverBaseUrl.getScheme() == null) {
        serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
    }// w  w w . j a  v a2s  . co m
    String accountName = username + "@" + serverBaseUrl.getHost();
    if (serverBaseUrl.getPort() >= 0) {
        accountName += ":" + serverBaseUrl.getPort();
    }
    return accountName;
}