本文整理匯總了Java中android.net.Uri.getHost方法的典型用法代碼示例。如果您正苦於以下問題:Java Uri.getHost方法的具體用法?Java Uri.getHost怎麽用?Java Uri.getHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.Uri
的用法示例。
在下文中一共展示了Uri.getHost方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onShortcutTap
import android.net.Uri; //導入方法依賴的package包/類
@Override
public void onShortcutTap(Uri uri) {
// Build root Uri from shortcut Uri
String rootUriString = uri.getScheme() + "://" + uri.getHost();
if (uri.getPort() != -1) {
rootUriString += ":" + uri.getPort();
}
rootUriString += "/";// important to end with "/"
Uri rootUri = Uri.parse(rootUriString);
Bundle args = new Bundle();
args.putParcelable(BrowserByNetwork.CURRENT_DIRECTORY, uri);
args.putString(BrowserByNetwork.TITLE
, uri.getLastPathSegment());
args.putString(BrowserByNetwork.SHARE_NAME, uri.getLastPathSegment());
Fragment f;
if (uri.getScheme().equals("smb")) {
f = Fragment.instantiate(getActivity(), BrowserBySmb.class.getCanonicalName(), args);
} else if (uri.getScheme().equals("upnp")) {
f = Fragment.instantiate(getActivity(), BrowserByUpnp.class.getCanonicalName(), args);
} else {
f = Fragment.instantiate(getActivity(), BrowserBySFTP.class.getCanonicalName(), args);
}
BrowserCategory category = (BrowserCategory) getActivity().getSupportFragmentManager().findFragmentById(R.id.category);
category.startContent(f);
}
示例2: onCreate
import android.net.Uri; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
if (intent != null) {
Uri data = getIntent().getData();
if (data != null) {
String host = data.getHost();
String path = data.getPath();
String param = data.getQueryParameter("key1");
String fragment = data.getFragment();
Log.e("TAG", "host:" + host);
Log.e("TAG", "path:" + path);
Log.e("TAG", "param:" + param);
Log.e("TAG", "fragment:" + fragment);
}
}
}
示例3: parse
import android.net.Uri; //導入方法依賴的package包/類
public static ShadowsocksConfig parse(String proxyInfo) throws Exception{
ShadowsocksConfig config=new ShadowsocksConfig();
Uri uri=Uri.parse(proxyInfo);
if(uri.getPort()==-1){
String base64String=uri.getHost();
proxyInfo="ss://"+ new String(Base64.decode(base64String.getBytes("ASCII"),Base64.DEFAULT));
uri=Uri.parse(proxyInfo);
}
String userInfoString=uri.getUserInfo();
if(userInfoString!=null){
String[] userStrings=userInfoString.split(":");
config.EncryptMethod=userStrings[0];
if(userStrings.length>=2){
config.Password=userStrings[1];
}
}
config.ServerAddress=new InetSocketAddress(uri.getHost(), uri.getPort());
config.Encryptor=EncryptorFactory.createEncryptorByConfig(config);
return config;
}
示例4: setChattingBackground
import android.net.Uri; //導入方法依賴的package包/類
public void setChattingBackground(String uriString, int color) {
if (uriString != null) {
Uri uri = Uri.parse(uriString);
if (uri.getScheme().equalsIgnoreCase("file") && uri.getPath() != null) {
listviewBk.setImageBitmap(getBackground(uri.getPath()));
} else if (uri.getScheme().equalsIgnoreCase("android.resource")) {
List<String> paths = uri.getPathSegments();
if (paths == null || paths.size() != 2) {
return;
}
String type = paths.get(0);
String name = paths.get(1);
String pkg = uri.getHost();
int resId = container.activity.getResources().getIdentifier(name, type, pkg);
if (resId != 0) {
listviewBk.setBackgroundResource(resId);
}
}
} else if (color != 0) {
listviewBk.setBackgroundColor(color);
}
}
示例5: StreamUriFinder
import android.net.Uri; //導入方法依賴的package包/類
public StreamUriFinder(Uri uri, Context context, Looper looper){
mUri = uri;
mDeviceID = uri.getHost();
abort = false;
mContext = context;
mUiHandler = new Handler(looper);
}
示例6: findDefaultTrafficStatsTag
import android.net.Uri; //導入方法依賴的package包/類
/**
* @return The hashcode of the URL's host component, or 0 if there is none.
*/
private static int findDefaultTrafficStatsTag(String url) {
if (!TextUtils.isEmpty(url)) {
Uri uri = Uri.parse(url);
if (uri != null) {
String host = uri.getHost();
if (host != null) {
return host.hashCode();
}
}
}
return 0;
}
示例7: getApkDownloadPath
import android.net.Uri; //導入方法依賴的package包/類
/**
* Get the full path for where an APK URL will be downloaded into.
*/
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());
}
示例8: onCreate
import android.net.Uri; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResultUri(null);
String url = getIntent().getStringExtra(EvernoteUtil.EXTRA_AUTHORIZATION_URL);
if (TextUtils.isEmpty(url)) {
CAT.w("no uri passed, return cancelled");
finish();
return;
}
Uri uri = Uri.parse(url);
if (!"https".equalsIgnoreCase(uri.getScheme())) {
CAT.w("https required, return cancelled");
finish();
return;
}
String host = uri.getHost();
if (!HOST_EVERNOTE.equalsIgnoreCase(host) && !HOST_SANDBOX.equalsIgnoreCase(host) && !HOST_CHINA.equalsIgnoreCase(host)) {
CAT.w("unacceptable host, return cancelled");
finish();
return;
}
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new WebViewFragment())
.commit();
}
}
示例9: parse
import android.net.Uri; //導入方法依賴的package包/類
public static HttpConnectConfig parse(String proxyInfo){
HttpConnectConfig config=new HttpConnectConfig();
Uri uri=Uri.parse(proxyInfo);
String userInfoString=uri.getUserInfo();
if(userInfoString!=null){
String[] userStrings=userInfoString.split(":");
config.UserName=userStrings[0];
if(userStrings.length>=2){
config.Password=userStrings[1];
}
}
config.ServerAddress=new InetSocketAddress(uri.getHost(), uri.getPort());
return config;
}
示例10: getTitleForDisplay
import android.net.Uri; //導入方法依賴的package包/類
/**
* Returns a title suitable for display for a link. If |title| is non-empty, this simply returns
* it. Otherwise, returns a shortened form of the URL.
*/
static String getTitleForDisplay(@Nullable String title, @Nullable String url) {
if (!TextUtils.isEmpty(title) || TextUtils.isEmpty(url)) {
return title;
}
Uri uri = Uri.parse(url);
String host = uri.getHost();
if (host == null) host = "";
String path = uri.getPath();
if (path == null || path.equals("/")) path = "";
title = host + path;
return title;
}
示例11: isInternalUri
import android.net.Uri; //導入方法依賴的package包/類
public static boolean isInternalUri(Uri uri) {
String host = uri.getHost();
host = host != null ? host.toLowerCase() : "";
return "tg".equals(uri.getScheme()) || "telegram.me".equals(host) || "telegram.dog".equals(host);
}
示例12: getDomainName
import android.net.Uri; //導入方法依賴的package包/類
public static String getDomainName(@NonNull Uri uri) {
LiCoreSDKUtils.checkNotNull(uri);
String domain = uri.getHost();
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
示例13: init
import android.net.Uri; //導入方法依賴的package包/類
private void init(Context context, Uri incomingUri) {
/* an URL from a click, NFC, QRCode scan, etc */
Uri uri = incomingUri;
if (uri == null) {
isValidRepo = false;
return;
}
Utils.debugLog(TAG, "Parsing incoming intent looking for repo: " + incomingUri);
// scheme and host should only ever be pure ASCII aka Locale.ENGLISH
String scheme = uri.getScheme();
host = uri.getHost();
port = uri.getPort();
if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) {
errorMessage = String.format(context.getString(R.string.malformed_repo_uri), uri);
isValidRepo = false;
return;
}
if (Arrays.asList("FDROIDREPO", "FDROIDREPOS").contains(scheme)) {
/*
* QRCodes are more efficient in all upper case, so QR URIs are
* encoded in all upper case, then forced to lower case. Checking if
* the special F-Droid scheme being all is upper case means it
* should be downcased.
*/
uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH));
} else if (uri.getPath().endsWith("/FDROID/REPO")) {
/*
* some QR scanners chop off the fdroidrepo:// and just try http://,
* then the incoming URI does not get downcased properly, and the
* query string is stripped off. So just downcase the path, and
* carry on to get something working.
*/
uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH));
}
// make scheme and host lowercase so they're readable in dialogs
scheme = scheme.toLowerCase(Locale.ENGLISH);
host = host.toLowerCase(Locale.ENGLISH);
// We only listen for /fdroid/archive or /fdroid/repo paths when receiving a HTTP(S) intent.
// For fdroidrepo(s) intents, we are less picky and will accept any path.
boolean isHttpScheme = TextUtils.equals("http", scheme) || TextUtils.equals("https", scheme);
String path = uri.getPath();
if (path == null || isHttpScheme && !(path.contains("/fdroid/archive") || path.contains("/fdroid/repo"))) {
isValidRepo = false;
return;
}
boolean isFdroidScheme = TextUtils.equals("fdroidrepo", scheme) || TextUtils.equals("fdroidrepos", scheme);
fingerprint = uri.getQueryParameter("fingerprint");
bssid = uri.getQueryParameter("bssid");
ssid = uri.getQueryParameter("ssid");
fromSwap = uri.getQueryParameter("swap") != null;
if (!isFdroidScheme && !isHttpScheme) {
isValidRepo = false;
return;
}
uriString = sanitizeRepoUri(uri);
isValidRepo = true;
}
示例14: callJava
import android.net.Uri; //導入方法依賴的package包/類
public static String callJava(Activity webLoader, WebView webView, String uriString) {
String methodName = "";
String apiName = "";
String param = "{}";
String port = "";
String error;
if (TextUtils.isEmpty(uriString)) {
return "uri不能為空";
}
Uri uri = Uri.parse(uriString);
if (uri == null) {
return "參數不合法";
}
apiName = uri.getHost();
param = uri.getQuery();
port = uri.getPort() + "";
methodName = uri.getPath();
if (TextUtils.isEmpty(apiName)) {
return "API_Name不能為空";
}
if (TextUtils.isEmpty(port)) {
return "callbackId不能為空";
}
methodName = methodName.replace("/", "");
if (TextUtils.isEmpty(methodName)) {
return "handlerName不能為空";
}
if (uriString.contains("#")) {
error = "參數中不能有#";
new Callback(webView, port).apply(getFailJSONObject(error));
return error;
}
if (!uriString.startsWith(EJS_SCHEME)) {
error = "SCHEME不正確";
new Callback(webView, port).apply(getFailJSONObject(error));
return error;
}
if (exposedMethods.containsKey(apiName)) {
HashMap<String, Method> methodHashMap = exposedMethods.get(apiName);
if (methodHashMap != null && methodHashMap.size() != 0 && methodHashMap.containsKey(methodName)) {
Method method = methodHashMap.get(methodName);
if (method != null) {
try {
method.invoke(null, webLoader, webView, new JSONObject(param), new Callback(webView, port));
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else {
//未注冊API
error = apiName + "未注冊";
new Callback(webView, port).apply(getFailJSONObject(error));
return error;
}
return null;
}
示例15: matches
import android.net.Uri; //導入方法依賴的package包/類
public boolean matches(final Uri resourceURI, final Uri pageURI) {
final String path = resourceURI.getPath();
if (path == null) {
return false;
}
// We need to handle webfonts first: if they are blocked, then whitelists don't matter.
// If they aren't blocked we still need to check domain blacklists below.
if (blockWebfonts) {
for (final String extension : WEBFONT_EXTENSIONS) {
if (path.endsWith(extension)) {
return true;
}
}
}
final String resourceURLString = resourceURI.toString();
// Cached whitelisted items can be permitted now (but blacklisted needs to wait for the override / entity list)
if (previouslyUnmatched.contains(resourceURLString)) {
return false;
}
if (entityList != null &&
entityList.isWhiteListed(pageURI, resourceURI)) {
// We must not cache entityList items (and/or if we did, we'd have to clear the cache
// on every single location change)
return false;
}
final String resourceHost = resourceURI.getHost();
final String pageHost = pageURI.getHost();
// Whitelist first party requests.
if (pageHost != null && pageHost.equals(resourceHost)) {
return false;
}
if (previouslyMatched.contains(resourceURLString)) {
return true;
}
final FocusString revhost = FocusString.create(resourceHost).reverse();
for (final Map.Entry<String, Trie> category : categories.entrySet()) {
if (enabledCategories.contains(category.getKey()) &&
category.getValue().findNode(revhost) != null) {
previouslyMatched.add(resourceURLString);
return true;
}
}
previouslyUnmatched.add(resourceURLString);
return false;
}