List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:com.yandex.disk.rest.example.ListExampleFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case GET_FILE_TO_UPLOAD: if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); if ("file".equalsIgnoreCase(uri.getScheme())) { uploadFile(uri.getPath()); } else { Toast.makeText(getActivity(), R.string.example_get_file_unsupported_scheme, Toast.LENGTH_LONG) .show();//from w w w .j a va 2 s . c o m } } break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.zhongzilu.bit100.view.activity.EditorActivity.java
private void getIntentData() { Intent intent = this.getIntent(); int flags = intent.getFlags(); if ((flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { if (intent.getAction() != null && Intent.ACTION_VIEW.equals(intent.getAction())) { if (SCHEME_FILE.equals(intent.getScheme())) { // // String type = getIntent().getType(); // mImportingUri=file:///storage/emulated/0/Vlog.xml intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri uri = intent.getData(); if (uri != null && SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) { // currentFilePath = FileUtils.uri2FilePath(getBaseContext(), uri); }/*from w w w.j a va2s. c om*/ } } } }
From source file:com.mobage.android.shellappsdk.sample.GameWebView.java
private boolean handleExternalDomainUrl(String url) { Uri uri = Uri.parse(url); String host = uri.getHost();/*w w w . j ava2 s .c om*/ if (mDomainWhiteList.containsHost(host)) { return false; } // No match - Sending Intent to External Browser if ("http".equalsIgnoreCase(uri.getScheme()) || "https".equalsIgnoreCase(uri.getScheme())) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (getContext() instanceof Activity) { getContext().startActivity(intent); } } return true; }
From source file:com.deliciousdroid.activity.FragmentBaseActivity.java
@Override @TargetApi(14)//from w w w .ja v a 2s.c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; mAccountManager = AccountManager.get(this); settings = PreferenceManager.getDefaultSharedPreferences(this); loadSettings(); init(); if (android.os.Build.VERSION.SDK_INT >= 14) { getActionBar().setHomeButtonEnabled(true); } Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) { if (intent.hasExtra(SearchManager.QUERY)) { Intent i = new Intent(this, MainSearchResults.class); i.putExtras(intent.getExtras()); startActivity(i); finish(); } else { onSearchRequested(); } } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) { Uri data = intent.getData(); String path = null; String tagname = null; if (data != null) { path = data.getPath(); tagname = data.getQueryParameter("tagname"); } if (data.getScheme() == null || !data.getScheme().equals("content")) { Intent i = new Intent(Intent.ACTION_VIEW, data); startActivity(i); finish(); } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment()) && intent.hasExtra(SearchManager.USER_QUERY)) { Intent viewBookmark = new Intent(this, ViewBookmark.class); viewBookmark.setAction(Intent.ACTION_VIEW); viewBookmark.setData(data); viewBookmark.removeExtra(SearchManager.USER_QUERY); Log.d("View Bookmark Uri", data.toString()); startActivity(viewBookmark); finish(); } else if (tagname != null) { Intent viewTags = new Intent(this, BrowseBookmarks.class); viewTags.setData(data); Log.d("View Tags Uri", data.toString()); startActivity(viewTags); finish(); } } }
From source file:com.ruesga.rview.ChangeDetailsActivity.java
@SuppressWarnings("Convert2streamapi") @Override/* w ww . j a v a 2 s . co m*/ protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBinding = DataBindingUtil.setContentView(this, R.layout.content); // Check we have valid arguments if (getIntent() == null) { finish(); return; } boolean forceSinglePanel = getIntent().getBooleanExtra(EXTRA_FORCE_SINGLE_PANEL, false); boolean isTwoPanel = getResources().getBoolean(R.bool.config_is_two_pane); if (!forceSinglePanel & isTwoPanel) { // Tablets have a two panel layout in landscape, so finish the current activity // to show the change in the proper activity finish(); return; } // Force single panel? if (forceSinglePanel) { setUseTwoPanel(false); setForceSinglePanel(true); } // Setup the title setupActivity(); if (getIntent().getData() != null) { Account account = Preferences.getAccount(this); if (account == null) { // Not ready to handle it notifyInvalidArgsAndFinish(); return; } // Check scheme Uri data = getIntent().getData(); String scheme = data.getScheme(); if (!scheme.equals(getPackageName())) { notifyInvalidArgsAndFinish(); return; } // Retrieve the host and the request id String host = data.getHost(); String query = StringHelper.getSafeLastPathSegment(data); if (TextUtils.isEmpty(query)) { notifyInvalidArgsAndFinish(); return; } ChangeQuery filter; switch (host) { case Constants.CUSTOM_URI_CHANGE: Pattern pattern = StringHelper.GERRIT_CHANGE; if (!pattern.matcher(query).matches()) { notifyInvalidArgsAndFinish(); return; } filter = new ChangeQuery().change(query); performGatherChangeId(filter); break; case Constants.CUSTOM_URI_CHANGE_ID: pattern = StringHelper.GERRIT_CHANGE_ID; String[] q = query.split(UriHelper.CUSTOM_URI_TOKENIZER); if (!pattern.matcher(q[0]).matches()) { notifyInvalidArgsAndFinish(); return; } filter = new ChangeQuery().change(q[0]); String file = rebuildFileInfo(q); String[] revAndBase = extractRevisionAndBase(q); performGatherChangeId(filter, revAndBase, file); break; case Constants.CUSTOM_URI_COMMIT: if (!StringHelper.GERRIT_COMMIT.matcher(query).matches()) { notifyInvalidArgsAndFinish(); return; } filter = new ChangeQuery().commit(query); performGatherChangeId(filter); break; default: try { int legacyChangeId = Integer.valueOf(query); filter = new ChangeQuery().change(String.valueOf(legacyChangeId)); performGatherChangeId(filter); return; } catch (NumberFormatException ex) { // Ignore. Not a valid change-id } notifyInvalidArgsAndFinish(); break; } } else { // Set the account if requested String accountId = getIntent().getStringExtra(Constants.EXTRA_ACCOUNT_HASH); if (!TextUtils.isEmpty(accountId)) { Preferences.setAccount(this, ModelHelper.getAccountFromHash(this, accountId)); } // Open the change directly int legacyChangeId = getIntent().getIntExtra(Constants.EXTRA_LEGACY_CHANGE_ID, -1); if (legacyChangeId == -1) { finish(); return; } String changeId = getIntent().getStringExtra(Constants.EXTRA_CHANGE_ID); performShowChange(savedInstanceState, legacyChangeId, changeId, null, null); } }
From source file:com.polyvi.xface.extension.XAppExt.java
private void setIntentByUri(Intent intent, Uri uri) { if (!XConstant.FILE_SCHEME.contains(uri.getScheme())) { intent.setData(uri);/*from ww w. j ava2s . c o m*/ } else { String mimeType = XFileUtils.getMIMEType(uri.toString()); intent.setDataAndType(uri, XStringUtils.isEmptyString(mimeType) ? "*/*" : mimeType); } }
From source file:com.microsoft.rightsmanagement.sampleapp.MainActivity.java
/** * Handle URI input./*w w w . ja v a2 s . c om*/ * * @param uri the uri * @throws FileNotFoundException the file not found exception */ private void handleUriInput(Uri uri) throws FileNotFoundException { String originalFileName; // If the URI scheme is a content type, this means we must attempt to retrieve the file name from the // content provider service. if (uri.getScheme().toString().equals("content")) { originalFileName = App.getFileNameFromContent(this, uri); } else { originalFileName = uri.getLastPathSegment().toString(); } if (App.isPTxtFile(originalFileName)) { InputStream inputStream = getContentResolver().openInputStream(uri); mMsipcTaskFragment.startContentConsumptionFromPtxtFileFormat(inputStream); } else if (App.isTxt2File(originalFileName)) { InputStream inputStream = getContentResolver().openInputStream(uri); mMsipcTaskFragment.startContentConsumptionFromMyOwnProtectedTextFileFormat(inputStream); } }
From source file:com.remobile.file.LocalFilesystem.java
@Override public LocalFilesystemURL toLocalUri(Uri inputURL) { if (!"file".equals(inputURL.getScheme())) { return null; }// w ww. j ava 2 s . co m File f = new File(inputURL.getPath()); // Removes and duplicate /s (e.g. file:///a//b/c) Uri resolvedUri = Uri.fromFile(f); String rootUriNoTrailingSlash = rootUri.getEncodedPath(); rootUriNoTrailingSlash = rootUriNoTrailingSlash.substring(0, rootUriNoTrailingSlash.length() - 1); if (!resolvedUri.getEncodedPath().startsWith(rootUriNoTrailingSlash)) { return null; } String subPath = resolvedUri.getEncodedPath().substring(rootUriNoTrailingSlash.length()); // Strip leading slash if (!subPath.isEmpty()) { subPath = subPath.substring(1); } Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost") .path(name); if (!subPath.isEmpty()) { b.appendEncodedPath(subPath); } if (f.isDirectory() || inputURL.getPath().endsWith("/")) { // Add trailing / for directories. b.appendEncodedPath(""); } return LocalFilesystemURL.parse(b.build()); }
From source file:com.taobao.weex.ui.component.WXImage.java
private void setBlurRadius(@NonNull String src, int blurRadius) { if (getInstance() != null && blurRadius != mBlurRadius) { Uri parsedUri = getInstance().rewriteUri(Uri.parse(src), URIAdapter.IMAGE); if (!Constants.Scheme.LOCAL.equals(parsedUri.getScheme())) { setRemoteSrc(parsedUri, blurRadius); }/* w ww . jav a2 s . c om*/ } }
From source file:com.taobao.weex.ui.component.WXImage.java
@WXComponentProp(name = Constants.Name.SRC) public void setSrc(String src) { if (src == null) { return;/* ww w . j ava2 s.co m*/ } ImageView image = getHostView(); if ("".equals(src) && image != null) { image.setImageDrawable(null); return; } if (image != null) { if (image.getDrawable() != null) { image.setImageDrawable(null); } } this.mSrc = src; WXSDKInstance instance = getInstance(); Uri rewrited = instance.rewriteUri(Uri.parse(src), URIAdapter.IMAGE); if (Constants.Scheme.LOCAL.equals(rewrited.getScheme())) { setLocalSrc(rewrited); } else { int blur = 0; if (getDomObject() != null) { String blurStr = getDomObject().getStyles().getBlur(); blur = parseBlurRadius(blurStr); } setRemoteSrc(rewrited, blur); } }