Java Code Examples for android.net.Uri#getScheme()
The following examples show how to use
android.net.Uri#getScheme() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowWidget.java From FirefoxReality with Mozilla Public License 2.0 | 7 votes |
/** * Filter out unwanted URIs, such as "chrome:", "about:", etc. * Ported from nsAndroidHistory::CanAddURI * See https://dxr.mozilla.org/mozilla-central/source/mobile/android/components/build/nsAndroidHistory.cpp#326 */ private boolean shouldStoreUri(@NonNull String uri) { Uri parsedUri = Uri.parse(uri); String scheme = parsedUri.getScheme(); if (scheme == null) { return false; } // Short-circuit most common schemes. if (scheme.equals("http") || scheme.equals("https")) { return true; } // Allow about about:reader uris. They are of the form: // about:reader?url=http://some.interesting.page/to/read.html if (uri.startsWith("about:reader")) { return true; } List<String> schemasToIgnore = Stream.of( "about", "imap", "news", "mailbox", "moz-anno", "moz-extension", "view-source", "chrome", "resource", "data", "javascript", "blob" ).collect(Collectors.toList()); return !schemasToIgnore.contains(scheme); }
Example 2
Source File: SchemeParser.java From mvvm-template with GNU General Public License v3.0 | 6 votes |
@Nullable private static Intent convert(@NonNull Context context, Uri data, boolean showRepoBtn) { if (data == null) return null; if (InputHelper.isEmpty(data.getHost()) || InputHelper.isEmpty(data.getScheme())) { String host = data.getHost(); if (InputHelper.isEmpty(host)) host = HOST_DEFAULT; String scheme = data.getScheme(); if (InputHelper.isEmpty(scheme)) scheme = PROTOCOL_HTTPS; String prefix = scheme + "://" + host; String path = data.getPath(); if (!InputHelper.isEmpty(path)) { if (path.charAt(0) == '/') { data = Uri.parse(prefix + path); } else { data = Uri.parse(prefix + '/' + path); } } else { data = Uri.parse(prefix); } } if (data.getPathSegments() != null && !data.getPathSegments().isEmpty()) { if (IGNORED_LIST.contains(data.getPathSegments().get(0))) return null; return getIntentForURI(context, data, showRepoBtn); } return null; }
Example 3
Source File: CordovaResourceApi.java From IoTgo_Android_App with MIT License | 6 votes |
public static int getUriType(Uri uri) { assertNonRelative(uri); String scheme = uri.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { return URI_TYPE_CONTENT; } if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) { return URI_TYPE_RESOURCE; } if (ContentResolver.SCHEME_FILE.equals(scheme)) { if (uri.getPath().startsWith("/android_asset/")) { return URI_TYPE_ASSET; } return URI_TYPE_FILE; } if ("data".equals(scheme)) { return URI_TYPE_DATA; } if ("http".equals(scheme)) { return URI_TYPE_HTTP; } if ("https".equals(scheme)) { return URI_TYPE_HTTPS; } return URI_TYPE_UNKNOWN; }
Example 4
Source File: ImageRequestTransformer.java From cathode with Apache License 2.0 | 6 votes |
@Override public Request transformRequest(Request request) { Uri uri = request.uri; if (uri == null) { return request; } final String scheme = uri.getScheme(); if (!SCHEMES.contains(scheme)) { return request; } final ImageType imageType = ImageType.fromValue(uri.getHost()); final String size = ImageSizeSelector.getInstance(context) .getSize(imageType, request.targetWidth, request.targetHeight); Uri newUri = uri.buildUpon().appendQueryParameter(QUERY_SIZE, size).build(); return request.buildUpon().setUri(newUri).build(); }
Example 5
Source File: LocationSettingsActivity.java From edslite with GNU General Public License v2.0 | 6 votes |
private Fragment getCreateLocationFragment() { Uri uri = getIntent().getData(); if(uri == null || uri.getScheme() == null) throw new RuntimeException("Location uri is not set"); switch (uri.getScheme()) { case EncFsLocationBase.URI_SCHEME: return new EncFsSettingsFragment(); case VeraCryptLocation.URI_SCHEME: case TrueCryptLocation.URI_SCHEME: case LUKSLocation.URI_SCHEME: case ContainerBasedLocation.URI_SCHEME: return new ContainerSettingsFragment(); default: throw new RuntimeException("Unknown location type"); } }
Example 6
Source File: CordovaResourceApi.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
public static int getUriType(Uri uri) { assertNonRelative(uri); String scheme = uri.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { return URI_TYPE_CONTENT; } if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) { return URI_TYPE_RESOURCE; } if (ContentResolver.SCHEME_FILE.equals(scheme)) { if (uri.getPath().startsWith("/android_asset/")) { return URI_TYPE_ASSET; } return URI_TYPE_FILE; } if ("data".equals(scheme)) { return URI_TYPE_DATA; } if ("http".equals(scheme)) { return URI_TYPE_HTTP; } if ("https".equals(scheme)) { return URI_TYPE_HTTPS; } return URI_TYPE_UNKNOWN; }
Example 7
Source File: MuPDFActivity.java From mupdf-android with GNU Affero General Public License v3.0 | 6 votes |
private void printDoc() { if (!core.fileFormat().startsWith("PDF")) { showInfo(getString(R.string.format_currently_not_supported)); return; } Intent myIntent = getIntent(); Uri docUri = myIntent != null ? myIntent.getData() : null; if (docUri == null) { showInfo(getString(R.string.print_failed)); } if (docUri.getScheme() == null) docUri = Uri.parse("file://"+docUri.toString()); Intent printIntent = new Intent(this, PrintDialogActivity.class); printIntent.setDataAndType(docUri, "aplication/pdf"); printIntent.putExtra("title", mFileName); startActivityForResult(printIntent, PRINT_REQUEST); }
Example 8
Source File: MediaPlayer.java From NetEasyNews with GNU General Public License v3.0 | 6 votes |
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { if (context == null || uri == null) throw new IllegalArgumentException(); String scheme = uri.getScheme(); if (scheme == null || scheme.equals("file")) { setDataSource(FileUtils.getPath(uri.toString())); return; } try { ContentResolver resolver = context.getContentResolver(); mFD = resolver.openAssetFileDescriptor(uri, "r"); if (mFD == null) return; setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor()); return; } catch (Exception e) { closeFD(); } setDataSource(uri.toString(), headers); }
Example 9
Source File: ConversationView.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
void deleteMessage (String packetId, String message) { if (!TextUtils.isEmpty(message)) { Uri deleteUri = Uri.parse(message); if (deleteUri.getScheme() != null && deleteUri.getScheme().equals("vfs")) { info.guardianproject.iocipher.File fileMedia = new info.guardianproject.iocipher.File(deleteUri.getPath()); fileMedia.delete(); } } Imps.deleteMessageInDb(mContext.getContentResolver(), packetId); requeryCursor(); }
Example 10
Source File: WXWebComponent.java From CrazyDaily with Apache License 2.0 | 5 votes |
protected void createWebView() { String origin = null; try { String bundleUrl = WXSDKManager.getInstance().getSDKInstance(getInstanceId()).getBundleUrl(); Uri uri = Uri.parse(bundleUrl); String scheme = uri.getScheme(); String authority = uri.getAuthority(); if (!TextUtils.isEmpty(scheme) && !TextUtils.isEmpty(authority)) { origin = scheme + "://" + authority; } } catch (Exception e) { // do noting } mWebView = new WXWebView(getContext(), origin); }
Example 11
Source File: FileListView.java From microMathematics with GNU General Public License v3.0 | 5 votes |
public final void Navigate(Uri uri, String posTo) { try { currentPosition = -1; listView.clearChoices(); listView.invalidateViews(); AdapterIf ca_new = null, ca = (AdapterIf) listView.getAdapter(); String scheme = uri.getScheme(); if (scheme == null) { scheme = ""; } if (ca == null || !scheme.equals(ca.getScheme())) { ca_new = commander.CreateAdapter(uri); listView.setAdapter((ListAdapter) ca_new); applySettings(); ca = ca_new; } ca.setMode(AdapterIf.MODE_SORTING | AdapterIf.MODE_SORT_DIR, adapterMode); ca.readSource(uri, Integer.toBinaryString(0) + (posTo == null ? "" : posTo)); statusPanel.setVisibility((ca instanceof AdapterHome) ? View.GONE : View.VISIBLE); statusPanelDivider.setVisibility(statusPanel.getVisibility()); statusBar.setText(ca.toString()); ViewUtils.Debug(this, "Current directory: " + ca.getUri().getPath()); } catch (Exception e) { e.printStackTrace(); } }
Example 12
Source File: Configuration.java From AppAuth-Android with Apache License 2.0 | 5 votes |
Uri getRequiredConfigWebUri(String propName) throws InvalidConfigurationException { Uri uri = getRequiredConfigUri(propName); String scheme = uri.getScheme(); if (TextUtils.isEmpty(scheme) || !("http".equals(scheme) || "https".equals(scheme))) { throw new InvalidConfigurationException( propName + " must have an http or https scheme"); } return uri; }
Example 13
Source File: CBrowserWindow.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
public void onDownloadStart(Context context, String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { Intent installIntent = new Intent(Intent.ACTION_VIEW); String filename = url; Uri path = Uri.parse(filename); if (path.getScheme() == null) { path = Uri.fromFile(new File(filename)); } installIntent.setDataAndType(path, mimetype); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (checkInstallApp(context, installIntent)) { try { context.startActivity(installIntent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, EUExUtil.getString("can_not_find_suitable_app_perform_this_operation"), Toast.LENGTH_SHORT).show(); } return; } } if (null != mDialog) { return; } mDialog = new EDownloadDialog(context, url); mDialog.userAgent = userAgent; mDialog.contentDisposition = contentDisposition; mDialog.mimetype = mimetype; mDialog.contentLength = contentLength; ECallback callback = new ECallback() { @Override public void callback(Object obj) { mDialog = null; } }; mDialog.setDoneCallback(callback); mDialog.show(); }
Example 14
Source File: NewConversationActivity.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
private void handleIntent() { Intent intent = getIntent(); String action = intent.getAction(); if(Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action)) { try { Uri uri = intent.getData(); if(uri != null) { String scheme = uri.getScheme(); if(scheme != null && scheme.equals(MAILTO) ) { String textToShare = getTextToShare(uri); MailTo mailto = MailTo.parse(uri.toString()); String recipientsList = mailto.getTo(); if(recipientsList != null && !recipientsList.isEmpty()) { String[] recipientsArray = recipientsList.split(","); if (recipientsArray.length >= 1) { String recipient = recipientsArray[0]; if (textToShare != null && !textToShare.isEmpty()) { getIntent().putExtra(TEXT_EXTRA, textToShare); } onContactSelected(DcContact.DC_CONTACT_ID_NEW_CONTACT, recipient); } } else { Intent shareIntent = new Intent(this, ShareActivity.class); shareIntent.putExtra(Intent.EXTRA_TEXT, textToShare); startActivity(shareIntent); finish(); } } } } catch(Exception e) { Log.e(TAG, "start activity from external 'mailto:' link failed", e); } } }
Example 15
Source File: ContentResolver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Open a stream on to the content associated with a content URI. If there * is no data associated with the URI, FileNotFoundException is thrown. * * <h5>Accepts the following URI schemes:</h5> * <ul> * <li>content ({@link #SCHEME_CONTENT})</li> * <li>android.resource ({@link #SCHEME_ANDROID_RESOURCE})</li> * <li>file ({@link #SCHEME_FILE})</li> * </ul> * * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information * on these schemes. * * @param uri The desired URI. * @return InputStream * @throws FileNotFoundException if the provided URI could not be opened. * @see #openAssetFileDescriptor(Uri, String) */ public final @Nullable InputStream openInputStream(@NonNull Uri uri) throws FileNotFoundException { Preconditions.checkNotNull(uri, "uri"); String scheme = uri.getScheme(); if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { // Note: left here to avoid breaking compatibility. May be removed // with sufficient testing. OpenResourceIdResult r = getResourceId(uri); try { InputStream stream = r.r.openRawResource(r.id); return stream; } catch (Resources.NotFoundException ex) { throw new FileNotFoundException("Resource does not exist: " + uri); } } else if (SCHEME_FILE.equals(scheme)) { // Note: left here to avoid breaking compatibility. May be removed // with sufficient testing. return new FileInputStream(uri.getPath()); } else { AssetFileDescriptor fd = openAssetFileDescriptor(uri, "r", null); try { return fd != null ? fd.createInputStream() : null; } catch (IOException e) { throw new FileNotFoundException("Unable to create stream"); } } }
Example 16
Source File: OtpParser.java From yubikit-android with Apache License 2.0 | 4 votes |
/** * Parses Uri from NDEF tag message and extracts the payload of it. * @param uri uri Generally uri format is https://my.yubico.com/yk/#<payload> * @return parsed OTP payload */ public static @Nullable String parseUri(@NonNull Uri uri) { if (uri.getScheme() == null) { return null; } final UriFormat format = getFormat(uri); String otpCode = null; if (format == UriFormat.YK_5) { otpCode = uri.getFragment(); } else if (format == UriFormat.YK_NEO) { otpCode = uri.getLastPathSegment(); } else { return null; } // if there is nothing in payload (only scheme and prefix) than otpCode data is empty // without this check we might take last path segment of YK_NEO format (/neo) if (uri.toString().length() == uri.getScheme().length() + format.prefix.length() + "://".length()) { return ""; } if (otpCode != null && otpCode.length() == 8) { // Some YubiKeys output 8 digit HOTP as scan codes, which need to be translated StringBuilder hotp = new StringBuilder(); for (byte code : otpCode.getBytes()) { if (code >= 0x1e && code < 0x27) { hotp.append(code - 0x1d); } else if (code == 0x27) { hotp.append("0"); } else { // Unknown character, not HOTP. return otpCode; } } return hotp.toString(); } return otpCode; }
Example 17
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static boolean handleProxyIntent(Activity activity, Intent intent) { if (intent == null) { return false; } try { if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { return false; } Uri data = intent.getData(); if (data != null) { String user = null; String password = null; String port = null; String address = null; String secret = null; String scheme = data.getScheme(); if (scheme != null) { if ((scheme.equals("http") || scheme.equals("https"))) { String host = data.getHost().toLowerCase(); if (host.equals("telegram.me") || host.equals("t.me") || host.equals("telegram.dog") || host.equals("telesco.pe")) { String path = data.getPath(); if (path != null) { if (path.startsWith("/socks") || path.startsWith("/proxy")) { address = data.getQueryParameter("server"); port = data.getQueryParameter("port"); user = data.getQueryParameter("user"); password = data.getQueryParameter("pass"); secret = data.getQueryParameter("secret"); } } } } else if (scheme.equals("tg")) { String url = data.toString(); if (url.startsWith("tg:proxy") || url.startsWith("tg://proxy") || url.startsWith("tg:socks") || url.startsWith("tg://socks")) { url = url.replace("tg:proxy", "tg://telegram.org").replace("tg://proxy", "tg://telegram.org").replace("tg://socks", "tg://telegram.org").replace("tg:socks", "tg://telegram.org"); data = Uri.parse(url); address = data.getQueryParameter("server"); port = data.getQueryParameter("port"); user = data.getQueryParameter("user"); password = data.getQueryParameter("pass"); secret = data.getQueryParameter("secret"); } } } if (!TextUtils.isEmpty(address) && !TextUtils.isEmpty(port)) { if (user == null) { user = ""; } if (password == null) { password = ""; } if (secret == null) { secret = ""; } showProxyAlert(activity, address, port, user, password, secret); return true; } } } catch (Exception ignore) {} return false; }
Example 18
Source File: TrackingProtectionWebViewClient.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Override public WebResourceResponse shouldInterceptRequest(final WebView view, final WebResourceRequest request) { if (!blockingEnabled) { return super.shouldInterceptRequest(view, request); } final Uri resourceUri = request.getUrl(); // shouldInterceptRequest() might be called _before_ onPageStarted or shouldOverrideUrlLoading // are called (this happens when the webview is first shown). However we are notified of the URL // via notifyCurrentURL in that case. final String scheme = resourceUri.getScheme(); if (!request.isForMainFrame() && !scheme.equals("http") && !scheme.equals("https")) { // Block any malformed non-http(s) URIs. WebView will already ignore things like market: URLs, // but not in all cases (malformed market: URIs, such as market:://... will still end up here). // (Note: data: URIs are automatically handled by WebView, and won't end up here either.) // file:// URIs are disabled separately by setting WebSettings.setAllowFileAccess() return new WebResourceResponse(null, null, null); } // WebView always requests a favicon, even though it won't be used anywhere. This check // isn't able to block all favicons (some of them will be loaded using <link rel="shortcut icon"> // with a custom URL which we can't match or detect), but reduces the amount of unnecessary // favicon loading that's performed. final String path = resourceUri.getPath(); if (path != null && path.endsWith("/favicon.ico")) { return new WebResourceResponse(null, null, null); } final UrlMatcher matcher = getMatcher(view.getContext()); // Don't block the main frame from being loaded. This also protects against cases where we // open a link that redirects to another app (e.g. to the play store). if ((!request.isForMainFrame()) && currentPageURL != null && matcher.matches(resourceUri, Uri.parse(currentPageURL))) { // Bandaid for issue #26: currentPageUrl can still be null, and needs to be investigated further. if (callback != null) { callback.countBlockedTracker(); } return new WebResourceResponse(null, null, null); } return super.shouldInterceptRequest(view, request); }
Example 19
Source File: NfcAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Set one or more {@link Uri}s to send using Android Beam (TM). Every * Uri you provide must have either scheme 'file' or scheme 'content'. * * <p>For the data provided through this method, Android Beam tries to * switch to alternate transports such as Bluetooth to achieve a fast * transfer speed. Hence this method is very suitable * for transferring large files such as pictures or songs. * * <p>The receiving side will store the content of each Uri in * a file and present a notification to the user to open the file * with a {@link android.content.Intent} with action * {@link android.content.Intent#ACTION_VIEW}. * If multiple URIs are sent, the {@link android.content.Intent} will refer * to the first of the stored files. * * <p>This method may be called at any time before {@link Activity#onDestroy}, * but the URI(s) are only made available for Android Beam when the * specified activity(s) are in resumed (foreground) state. The recommended * approach is to call this method during your Activity's * {@link Activity#onCreate} - see sample * code below. This method does not immediately perform any I/O or blocking work, * so is safe to call on your main thread. * * <p>{@link #setBeamPushUris} and {@link #setBeamPushUrisCallback} * have priority over both {@link #setNdefPushMessage} and * {@link #setNdefPushMessageCallback}. * * <p>If {@link #setBeamPushUris} is called with a null Uri array, * and/or {@link #setBeamPushUrisCallback} is called with a null callback, * then the Uri push will be completely disabled for the specified activity(s). * * <p>Code example: * <pre> * protected void onCreate(Bundle savedInstanceState) { * super.onCreate(savedInstanceState); * NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); * if (nfcAdapter == null) return; // NFC not available on this device * nfcAdapter.setBeamPushUris(new Uri[] {uri1, uri2}, this); * }</pre> * And that is it. Only one call per activity is necessary. The Android * OS will automatically release its references to the Uri(s) and the * Activity object when it is destroyed if you follow this pattern. * * <p>If your Activity wants to dynamically supply Uri(s), * then set a callback using {@link #setBeamPushUrisCallback} instead * of using this method. * * <p class="note">Do not pass in an Activity that has already been through * {@link Activity#onDestroy}. This is guaranteed if you call this API * during {@link Activity#onCreate}. * * <p class="note">If this device does not support alternate transports * such as Bluetooth or WiFI, calling this method does nothing. * * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission. * * @param uris an array of Uri(s) to push over Android Beam * @param activity activity for which the Uri(s) will be pushed * @throws UnsupportedOperationException if FEATURE_NFC is unavailable. */ public void setBeamPushUris(Uri[] uris, Activity activity) { synchronized (NfcAdapter.class) { if (!sHasNfcFeature) { throw new UnsupportedOperationException(); } } if (activity == null) { throw new NullPointerException("activity cannot be null"); } if (uris != null) { for (Uri uri : uris) { if (uri == null) throw new NullPointerException("Uri not " + "allowed to be null"); String scheme = uri.getScheme(); if (scheme == null || (!scheme.equalsIgnoreCase("file") && !scheme.equalsIgnoreCase("content"))) { throw new IllegalArgumentException("URI needs to have " + "either scheme file or scheme content"); } } } mNfcActivityManager.setNdefPushContentUri(activity, uris); }
Example 20
Source File: LinkResolverDefTest.java From Markwon with Apache License 2.0 | 3 votes |
@Test public void scheme_present() { // when scheme is present, it won't be touched final String link = "whatnot://hey/ho"; final Uri uri = resolve(link); final String scheme = uri.getScheme(); assertEquals(uri.toString(), "whatnot", scheme); assertEquals(Uri.parse(link), uri); }