List of usage examples for android.net Uri getHost
@Nullable public abstract String getHost();
From source file:com.mobicage.rogerthat.AddFriendsActivity.java
private void inviteViaSMS(final Contact contact) { T.UI();// w w w .java2s . c o m MyIdentity identity = mService.getIdentityStore().getIdentity(); String shortLink = identity.getShortLink(); String installLink = CloudConstants.HTTPS_BASE_URL + CloudConstants.INSTALL_URL + "?a=" + AppConstants.APP_ID; String body; if (shortLink == null) { body = getString(R.string.friend_sms_invitation_no_url, contact.name, installLink, getString(R.string.app_name)); } else { Uri shortLinkUri = Uri.parse(shortLink); String shortLinkLC = shortLinkUri.getScheme().toLowerCase() + "://" + shortLinkUri.getHost().toLowerCase(); shortLink = shortLinkLC + shortLink.substring(shortLinkLC.length()); String secret = mFriendsPlugin.popInvitationSecret(); if (secret != null) { shortLink += "?s=" + secret; mFriendsPlugin.logInvitationSecretSent(secret, contact.email); } body = getString(R.string.friend_sms_invitation, contact.name, installLink, shortLink, getString(R.string.app_name)); } final SMSManager smsManager = new SMSManager(this); try { smsManager.sendSMS(contact.primaryPhoneNumber, body); } finally { smsManager.close(); } UIUtils.showLongToast(mService, mService.getString(R.string.invitation_sent_successfully)); mFriendsPlugin.getStore().insertPendingInvitation(contact.primaryPhoneNumber); }
From source file:org.mozilla.focus.webkit.matcher.UrlMatcher.java
public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; }/*from ww w .j av a 2 s .c o m*/ // 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(); 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; }
From source file:org.openhab.habdroid.ui.OpenHABMainActivity.java
/** * This method processes new intents generated by NFC subsystem * * @param nfcData - a data which NFC subsystem got from the NFC tag *//*from w ww . j av a2s. c o m*/ public void onNfcTag(String nfcData) { Log.d(TAG, "onNfcTag()"); Uri openHABURI = Uri.parse(nfcData); Log.d(TAG, "NFC Scheme = " + openHABURI.getScheme()); Log.d(TAG, "NFC Host = " + openHABURI.getHost()); Log.d(TAG, "NFC Path = " + openHABURI.getPath()); String nfcItem = openHABURI.getQueryParameter("item"); String nfcCommand = openHABURI.getQueryParameter("command"); String nfcItemType = openHABURI.getQueryParameter("itemType"); // If there is no item parameter it means tag contains only sitemap page url if (TextUtils.isEmpty(nfcItem)) { Log.d(TAG, "This is a sitemap tag without parameters"); // Form the new sitemap page url String newPageUrl = openHABBaseUrl + "rest/sitemaps" + openHABURI.getPath(); // Check if we have this page in stack? mPendingNfcPage = newPageUrl; } else { Log.d(TAG, "Target item = " + nfcItem); sendItemCommand(nfcItem, nfcCommand); // if mNfcData is not empty, this means we were launched with NFC touch // and thus need to autoexit after an item action if (!TextUtils.isEmpty(mNfcData)) finish(); } mNfcData = ""; }
From source file:org.sufficientlysecure.keychain.ui.DecryptListFragment.java
@Override public void onQueuedOperationError(InputDataResult result) { final Uri uri = mCurrentInputUri; mCurrentInputUri = null;// w w w . ja va 2 s.c om Activity activity = getActivity(); if (activity != null && "com.fsck.k9.attachmentprovider".equals(uri.getHost())) { Toast.makeText(getActivity(), R.string.error_reading_k9, Toast.LENGTH_LONG).show(); } mAdapter.addResult(uri, result); cryptoOperation(); }
From source file:com.appunite.websocket.WebSocket.java
/** * This method will be alive until error occur or interrupt was executed. * This method always throws some exception. (not thread safe) * // w w w . j a va 2s .com * @param uri * uri of websocket * @throws UnknownHostException * when could not connect to selected host * @throws IOException * thrown when I/O exception occur * @throws WrongWebsocketResponse * thrown when wrong web socket response received * @throws InterruptedException * thrown when interrupt method was invoked */ public void connect(Uri uri) throws IOException, WrongWebsocketResponse, InterruptedException { checkNotNull(uri, "Uri cannot be null"); try { synchronized (mLockObj) { checkState(State.DISCONNECTED.equals(mState), "connect could be called only if disconnected"); SocketFactory factory; if (isSsl(uri)) { factory = SSLSocketFactory.getDefault(); } else { factory = SocketFactory.getDefault(); } mSocket = factory.createSocket(); mState = State.CONNECTING; mLockObj.notifyAll(); } mSocket.connect(new InetSocketAddress(uri.getHost(), getPort(uri))); mInputStream = new WebSocketReader(mSocket.getInputStream()); mOutputStream = new WebSocketWriter(mSocket.getOutputStream()); String secret = generateHandshakeSecret(); writeHeaders(uri, secret); readHandshakeHeaders(secret); } catch (IOException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw e; } } } finally { synchronized (mLockObj) { mState = State.DISCONNECTED; mLockObj.notifyAll(); } } try { synchronized (mLockObj) { mState = State.CONNECTED; mLockObj.notifyAll(); } mListener.onConnected(); //noinspection InfiniteLoopStatement for (;;) { doRead(); } } catch (NotConnectedException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw new RuntimeException(); } } } catch (IOException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw e; } } } finally { synchronized (mLockObj) { while (mWriting != 0) { mLockObj.wait(); } mState = State.DISCONNECTED; mLockObj.notifyAll(); } } }
From source file:org.xbmc.kore.ui.RemoteActivity.java
/** * Handles the intent that started this activity, namely to start playing something on Kodi * @param intent Start intent for the activity *///from w w w .j a v a2 s . c o m private void handleStartIntent(Intent intent) { final String action = intent.getAction(); // Check action if ((action == null) || !(action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_VIEW))) return; Uri videoUri = null; if (action.equals(Intent.ACTION_SEND)) { // Get the URI, which is stored in Extras videoUri = getYouTubeUri(intent.getStringExtra(Intent.EXTRA_TEXT)); if (videoUri == null) return; } else if (action.equals(Intent.ACTION_VIEW)) { if (intent.getData() == null) return; videoUri = Uri.parse(intent.getData().toString()); } final String videoId = getVideoId(videoUri); if (videoId == null) { Toast.makeText(RemoteActivity.this, R.string.error_share_video, Toast.LENGTH_SHORT).show(); return; } final String kodiAddonUrl = "plugin://plugin.video." + (videoUri.getHost().endsWith("vimeo.com") ? "vimeo" : "youtube") + "/play/?video_id=" + videoId; // Check if any video player is active and clear the playlist before queuing if so final HostConnection connection = hostManager.getConnection(); final Handler callbackHandler = new Handler(); Player.GetActivePlayers getActivePlayers = new Player.GetActivePlayers(); getActivePlayers.execute(connection, new ApiCallback<ArrayList<PlayerType.GetActivePlayersReturnType>>() { @Override public void onSuccess(ArrayList<PlayerType.GetActivePlayersReturnType> result) { boolean videoIsPlaying = false; for (PlayerType.GetActivePlayersReturnType player : result) { if (player.type.equals(PlayerType.GetActivePlayersReturnType.VIDEO)) videoIsPlaying = true; } if (!videoIsPlaying) { // Clear the playlist clearPlaylistAndQueueFile(kodiAddonUrl, connection, callbackHandler); } else { queueFile(kodiAddonUrl, false, connection, callbackHandler); } } @Override public void onError(int errorCode, String description) { LogUtils.LOGD(TAG, "Couldn't get active player when handling start intent."); Toast.makeText(RemoteActivity.this, String.format(getString(R.string.error_get_active_player), description), Toast.LENGTH_SHORT) .show(); } }, callbackHandler); intent.setAction(null); }
From source file:gc.david.dfm.ui.activity.MainActivity.java
private void handleViewPositionIntent(final Intent intent) { final Uri uri = intent.getData(); DFMLogger.logMessage(TAG, "handleViewPositionIntent uri=" + uri.toString()); final String uriScheme = uri.getScheme(); if (uriScheme.equals("geo")) { handleGeoSchemeIntent(uri);/*from ww w . j ava 2 s .c o m*/ } else if ((uriScheme.equals("http") || uriScheme.equals("https")) && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude handleMapsHostIntent(uri); } else { final Exception exception = new Exception("Imposible tratar la query " + uri.toString()); DFMLogger.logException(exception); toastIt("Unable to parse address", this); } }
From source file:org.transdroid.core.gui.TorrentsActivity.java
/** * If required, add torrents from the supplied intent extras. *//*from ww w . j a va2s .com*/ protected void addFromIntent() { Intent intent = getIntent(); Uri dataUri = intent.getData(); String data = intent.getDataString(); String action = intent.getAction(); // Adding multiple torrents at the same time (as found in the Intent extras Bundle) if (action != null && action.equals("org.transdroid.ADD_MULTIPLE")) { // Intent should have some extras pointing to possibly multiple torrents String[] urls = intent.getStringArrayExtra("TORRENT_URLS"); String[] titles = intent.getStringArrayExtra("TORRENT_TITLES"); if (urls != null) { for (int i = 0; i < urls.length; i++) { String title = (titles != null && titles.length >= i ? titles[i] : NavigationHelper.extractNameFromUri(Uri.parse(urls[i]))); if (intent.hasExtra("PRIVATE_SOURCE")) { // This is marked by the Search Module as being a private source site; get the url locally first addTorrentFromPrivateSource(urls[i], title, intent.getStringExtra("PRIVATE_SOURCE")); } else { addTorrentByUrl(urls[i], title); } } } return; } // Add a torrent from a local or remote data URI? if (dataUri == null) { return; } if (dataUri.getScheme() == null) { SnackbarManager .show(Snackbar.with(this).text(R.string.error_invalid_url_form).colorResource(R.color.red)); return; } // Get torrent title String title = NavigationHelper.extractNameFromUri(dataUri); if (intent.hasExtra("TORRENT_TITLE")) { title = intent.getStringExtra("TORRENT_TITLE"); } // Adding a torrent from the Android downloads manager if (dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { addTorrentFromDownloads(dataUri, title); return; } // Adding a torrent from http or https URL if (dataUri.getScheme().equals("http") || dataUri.getScheme().equals("https")) { String privateSource = getIntent().getStringExtra("PRIVATE_SOURCE"); WebsearchSetting match = null; if (privateSource == null) { // Check if the target URL is also defined as a web search in the user's settings List<WebsearchSetting> websearches = applicationSettings.getWebsearchSettings(); for (WebsearchSetting setting : websearches) { Uri uri = Uri.parse(setting.getBaseUrl()); if (uri.getHost() != null && uri.getHost().equals(dataUri.getHost())) { match = setting; break; } } } // If the URL is also a web search and it defines cookies, use the cookies by downloading the targeted // torrent file (while supplies the cookies to the HTTP request) instead of sending the URL directly to the // torrent client. If instead it is marked (by the Torrent Search module) as being form a private site, use // the Search Module instead to download the url locally first. if (match != null && match.getCookies() != null) { addTorrentFromWeb(data, match, title); } else if (privateSource != null) { addTorrentFromPrivateSource(data, title, privateSource); } else { // Normally send the URL to the torrent client addTorrentByUrl(data, title); } return; } // Adding a torrent from magnet URL if (dataUri.getScheme().equals("magnet")) { addTorrentByMagnetUrl(data, title); return; } // Adding a local .torrent file; the title we show is just the file name if (dataUri.getScheme().equals("file")) { addTorrentByFile(data, title); } }
From source file:com.mediatek.systemupdate.HttpManager.java
private HttpResponse doPost(String url, Map<String, String> headers, ArrayList<BasicNameValuePair> bnvpa) { Xlog.i(TAG, "doPost, url = " + url + ", mCookies = " + mCookies); HttpContext localcontext = new BasicHttpContext(); if (mCookies != null) { localcontext.setAttribute(ClientContext.COOKIE_STORE, mCookies); }//from w w w . ja v a 2s . c o m HttpResponse response = null; try { HttpHost host = null; HttpPost httpPost = null; if (url.contains("https")) { Uri uri = Uri.parse(url); host = new HttpHost(uri.getHost(), PORT_NUMBER, uri.getScheme()); httpPost = new HttpPost(uri.getPath()); } else { httpPost = new HttpPost(url); } if (headers != null) { for (Map.Entry<String, String> entry : headers.entrySet()) { httpPost.addHeader(entry.getKey(), entry.getValue()); } } if (bnvpa != null) { httpPost.setEntity(new UrlEncodedFormEntity(bnvpa)); } DefaultHttpClient httpClient = new DefaultHttpClient(mHttpConnMgr, mHttpParam); try { if (url.contains("https")) { Xlog.i(TAG, "doPost, https"); response = httpClient.execute(host, httpPost); } else { Xlog.i(TAG, "doPost, http"); Xlog.i(TAG, "mHttpClient =" + httpClient + "httpPost = " + httpPost + "localcontext = " + localcontext); response = httpClient.execute(httpPost, localcontext); } if (mCookies == null) { mCookies = httpClient.getCookieStore(); Xlog.i(TAG, "mCookies size = " + mCookies.getCookies().size()); } return response; } catch (ConnectTimeoutException e) { e.printStackTrace(); mErrorCode = HTTP_RESPONSE_NETWORK_ERROR; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); mErrorCode = HTTP_RESPONSE_NETWORK_ERROR; } catch (IOException e) { e.printStackTrace(); mErrorCode = HTTP_RESPONSE_NETWORK_ERROR; } return response; }
From source file:org.tomahawk.tomahawk_android.activities.TomahawkMainActivity.java
private void handleIntent(Intent intent) { if (SHOW_PLAYBACKFRAGMENT_ON_STARTUP.equals(intent.getAction())) { // if this Activity is being shown after the user clicked the notification if (mSlidingUpPanelLayout != null) { mSlidingUpPanelLayout.expandPanel(); }//from w w w. j av a 2s . c o m } if (intent.hasExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE)) { Bundle bundle = new Bundle(); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_STATIC_SMALL); FragmentUtils.replace(this, PreferencePagerFragment.class, bundle); } if (intent.getData() != null) { final Uri data = intent.getData(); intent.setData(null); List<String> pathSegments = data.getPathSegments(); String host = data.getHost(); String scheme = data.getScheme(); if ((scheme != null && (scheme.equals("spotify") || scheme.equals("tomahawk"))) || (host != null && (host.contains("spotify.com") || host.contains("hatchet.is") || host.contains("toma.hk") || host.contains("beatsmusic.com") || host.contains("deezer.com") || host.contains("rdio.com") || host.contains("soundcloud.com")))) { PipeLine.get().lookupUrl(data.toString()); } else if ((pathSegments != null && pathSegments.get(pathSegments.size() - 1).endsWith(".xspf")) || (intent.getType() != null && intent.getType().equals("application/xspf+xml"))) { TomahawkRunnable r = new TomahawkRunnable(TomahawkRunnable.PRIORITY_IS_INFOSYSTEM_HIGH) { @Override public void run() { Playlist pl = XspfParser.parse(data); if (pl != null) { final Bundle bundle = new Bundle(); bundle.putString(TomahawkFragment.PLAYLIST, pl.getCacheKey()); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_DYNAMIC); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { FragmentUtils.replace(TomahawkMainActivity.this, PlaylistEntriesFragment.class, bundle); } }); } } }; ThreadManager.get().execute(r); } else if (pathSegments != null && (pathSegments.get(pathSegments.size() - 1).endsWith(".axe") || pathSegments.get(pathSegments.size() - 1).endsWith(".AXE"))) { InstallPluginConfigDialog dialog = new InstallPluginConfigDialog(); Bundle args = new Bundle(); args.putString(InstallPluginConfigDialog.PATH_TO_AXE_URI_STRING, data.toString()); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), null); } else { String albumName; String trackName; String artistName; try { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this, data); albumName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); artistName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); trackName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); retriever.release(); } catch (Exception e) { Log.e(TAG, "handleIntent: " + e.getClass() + ": " + e.getLocalizedMessage()); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { String msg = TomahawkApp.getContext().getString(R.string.invalid_file); Toast.makeText(TomahawkApp.getContext(), msg, Toast.LENGTH_LONG).show(); } }); return; } if (TextUtils.isEmpty(trackName) && pathSegments != null) { trackName = pathSegments.get(pathSegments.size() - 1); } Query query = Query.get(trackName, albumName, artistName, false); Result result = Result.get(data.toString(), query.getBasicTrack(), UserCollectionStubResolver.get()); float trackScore = query.howSimilar(result); query.addTrackResult(result, trackScore); Bundle bundle = new Bundle(); List<Query> queries = new ArrayList<>(); queries.add(query); Playlist playlist = Playlist.fromQueryList(TomahawkMainActivity.getSessionUniqueStringId(), false, "", "", queries); bundle.putString(TomahawkFragment.PLAYLIST, playlist.getCacheKey()); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_DYNAMIC); FragmentUtils.replace(TomahawkMainActivity.this, PlaylistEntriesFragment.class, bundle); } } }