List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:com.github.barteksc.sample.PDFViewActivity.java
public String getFileName(Uri uri) { String result = null;/*from w w w . j a v a 2 s . c om*/ if (uri.getScheme().equals("content")) { Cursor cursor = getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getLastPathSegment(); } return result; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
@Override public void activate(Context context, SignedObj obj) { JSONObject content = obj.getJson();/*from ww w .j av a 2 s .c o m*/ //linkify should have picked it up already but if we are in TV mode we //still need to activate Intent intent = new Intent(Intent.ACTION_VIEW); String text = content.optString(URI); //some shared links come in with two lines of text "title\nuri" //for example google maps does this and passes that same value as both the //uri and title //launch the first thing that looks like a link Matcher m = p.matcher(text); while (m.find()) { Uri uri = Uri.parse(m.group()); String scheme = uri.getScheme(); if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) { String type = content.optString(MIME_TYPE); if (type != null && type.length() > 0) { intent.setDataAndType(uri, type); } else { intent.setData(uri); } if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } try { context.startActivity(intent); } catch (ActivityNotFoundException e) { String msg; if (type != null) msg = "A third party application that supports " + type + " is required."; else msg = "A third party application that supports " + uri.getScheme() + " is required."; Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } return; } } }
From source file:com.remobile.file.ContentFilesystem.java
@Override public LocalFilesystemURL toLocalUri(Uri inputURL) { if (!"content".equals(inputURL.getScheme())) { return null; }/*w w w .ja v a 2 s . com*/ String subPath = inputURL.getEncodedPath(); if (subPath.length() > 0) { subPath = subPath.substring(1); } Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost") .path(name).appendPath(inputURL.getAuthority()); if (subPath.length() > 0) { b.appendEncodedPath(subPath); } Uri localUri = b.encodedQuery(inputURL.getEncodedQuery()).encodedFragment(inputURL.getEncodedFragment()) .build(); return LocalFilesystemURL.parse(localUri); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.GBWebClient.java
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri parsedUri = Uri.parse(url); if (parsedUri.getScheme().startsWith("http")) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); GBApplication.getContext().startActivity(i); } else if (parsedUri.getScheme().startsWith("pebblejs")) { url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); view.loadUrl(url);/* www.j a v a2s.c o m*/ } else if (parsedUri.getScheme().equals("data")) { //clay view.loadUrl(url); } else { LOG.debug("WEBVIEW Ignoring unhandled scheme: " + parsedUri.getScheme()); } return true; }
From source file:com.odesk.example_odeskapi.MyActivity.java
/** * Callback once we are done with the authorization of this app * @param intent/*from ww w . j a va 2 s .c om*/ */ @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); // Verify OAuth callback Uri uri = intent.getData(); if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) { String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER); new ODeskRetrieveAccessTokenTask().execute(verifier); } }
From source file:com.upwork.example_upworkapi.MyActivity.java
/** * Callback once we are done with the authorization of this app * @param intent//from ww w . ja v a 2s.co m */ @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); // Verify OAuth callback Uri uri = intent.getData(); if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) { String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER); new UpworkRetrieveAccessTokenTask().execute(verifier); } }
From source file:org.zywx.wbpalmstar.engine.EDownloadDialog.java
private void downloadDone() { stopDownload();/*from ww w . j av a2 s. com*/ Intent installIntent = new Intent(Intent.ACTION_VIEW); String filename = mTmpFile.getAbsolutePath(); 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); try { getContext().startActivity(installIntent); } catch (Exception e) { e.printStackTrace(); mProgressHandler.sendMessage(mProgressHandler.obtainMessage(-2, "?")); } }
From source file:com.zoterodroid.activity.BrowseCitations.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_bookmarks); mAccountManager = AccountManager.get(this); mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0]; mContext = this; Log.d("browse bookmarks", getIntent().getDataString()); Uri data = getIntent().getData(); String scheme = data.getScheme(); String path = data.getPath(); Log.d("path", path); String username = data.getQueryParameter("username"); String tagname = data.getQueryParameter("tagname"); String recent = data.getQueryParameter("recent"); myself = mAccount.name.equals(username); ArrayList<Citation> citationList = new ArrayList<Citation>(); if (scheme.equals("content") && path.equals("/citations") && myself) { try {// w w w .ja v a 2 s . c o m String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key, Citation.Creator_Summary, Citation.Item_Type }; String selection = null; String sortorder = null; selection = Citation.Account + " = '" + username + "'"; Uri citations = Citation.CONTENT_URI; Cursor c = managedQuery(citations, projection, selection, null, sortorder); if (c.moveToFirst()) { int idColumn = c.getColumnIndex(Citation._ID); int titleColumn = c.getColumnIndex(Citation.Title); int keyColumn = c.getColumnIndex(Citation.Key); int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary); int itemTypeColumn = c.getColumnIndex(Citation.Item_Type); do { Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn), c.getString(keyColumn), c.getString(creatorSummaryColumn), c.getString(itemTypeColumn)); citationList.add(b); } while (c.moveToNext()); } setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList)); } catch (Exception e) { } } lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); /* Add Context-Menu listener to the ListView. */ lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("Actions"); if (myself) { menu.add(Menu.NONE, 0, Menu.NONE, "Delete"); } else { menu.add(Menu.NONE, 1, Menu.NONE, "Add"); } } }); }
From source file:com.xabber.android.ui.ContactViewer.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { // View information about contact from system contact list Uri data = getIntent().getData(); if (data != null && "content".equals(data.getScheme())) { List<String> segments = data.getPathSegments(); if (segments.size() == 2 && "data".equals(segments.get(0))) { Long id;/*from www .j a v a 2 s .c om*/ try { id = Long.valueOf(segments.get(1)); } catch (NumberFormatException e) { id = null; } if (id != null) // FIXME: Will be empty while application is loading for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) if (id.equals(rosterContact.getViewId())) { account = rosterContact.getAccount(); bareAddress = rosterContact.getUser(); break; } } } } else { account = getAccount(getIntent()); bareAddress = Jid.getBareAddress(getUser(getIntent())); } if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) { bareAddress = Jid.getBareAddress(AccountManager.getInstance().getAccount(account).getRealJid()); } if (account == null || bareAddress == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); finish(); return; } if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.scrollable_container, ContactVcardViewerFragment.newInstance(account, bareAddress)) .commit(); } contactTitleExpandableToolbarInflater = new ContactTitleExpandableToolbarInflater(this); AbstractContact bestContact = RosterManager.getInstance().getBestContact(account, bareAddress); contactTitleExpandableToolbarInflater.onCreate(bestContact); View contactTitleView = findViewById(R.id.expandable_contact_title); contactTitleView.findViewById(R.id.status_icon).setVisibility(View.GONE); contactTitleView.findViewById(R.id.status_text).setVisibility(View.GONE); contactNameView = (TextView) contactTitleView.findViewById(R.id.name); Toolbar toolbar = contactTitleExpandableToolbarInflater.getToolbar(); toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NavUtils.navigateUpFromSameTask(ContactViewer.this); } }); }
From source file:felixwiemuth.lincal.ui.HtmlDialogFragment.java
private boolean loadUrl(WebView webView, Uri uri) { if (uri.getScheme().equals("file")) { webView.loadUrl(uri.toString()); } else if (uri.getScheme().equals("action")) { List<String> segments = uri.getPathSegments(); if (segments.isEmpty()) { throw new RuntimeException("Error in WebView: No action name provided."); } else {/* w ww.j av a2 s . co m*/ handleAction(segments.get(0), segments.subList(1, segments.size())); } } else { // If the URI is not pointing to a local file, open with an ACTION_VIEW Intent webView.getContext().startActivity(new Intent(Intent.ACTION_VIEW, uri)); } return true; // in both cases we handle the link manually }