List of usage examples for android.net Uri getSchemeSpecificPart
public abstract String getSchemeSpecificPart();
From source file:gc.david.dfm.ui.activity.MainActivity.java
private void handleGeoSchemeIntent(final Uri uri) { final String schemeSpecificPart = uri.getSchemeSpecificPart(); final Matcher matcher = getMatcherForUri(schemeSpecificPart); if (matcher.find()) { if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) { if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label) setDestinationPosition(matcher); } else { // Manage geo:0,0?q=my+street+address String destination = Uri.decode(uri.getQuery()).replace('+', ' '); destination = destination.replace("q=", ""); // TODO check this ugly workaround addressPresenter.searchPositionByName(destination); searchMenuItem.collapseActionView(); mustShowPositionWhenComingFromOutside = true; }/*from w w w. j av a 2s.c o m*/ } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom setDestinationPosition(matcher); } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); DFMLogger.logException(noSuchFieldException); toastIt("Unable to parse address", this); } }
From source file:org.restcomm.android.olympus.MainActivity.java
private void handleExternalCall() { // We have connectivity (either wifi or cellular), check if we have any external call requests and service it GlobalPreferences globalPreferences = new GlobalPreferences(getApplicationContext()); String externalCallUriString = globalPreferences.getExternalCallUri(); if (!externalCallUriString.isEmpty()) { Uri externalCallUri = Uri.parse(externalCallUriString); String parsedUriString = ""; if (externalCallUri.getScheme().contains("sip")) { // either 'sip' or 'restcomm-sip' // normalize 'restcomm-sip' and replace with 'sip' //String normalized = externalCallUriString.replace("restcomm-sip", "sip"); // also replace '://' with ':' so that the SIP stack can understand it //parsedUriString = normalized.replace("://", ":"); parsedUriString = externalCallUriString.replace("restcomm-sip", "sip"); } else {/*from www . j a v a 2s . c o m*/ // either 'tel', 'restcomm-tel', 'client' or 'restcomm-client'. Return just the host part, like 'bob' or '1235' that the Restcomm SDK can handle parsedUriString = externalCallUri.getSchemeSpecificPart(); } Intent intent = new Intent(this, CallActivity.class); intent.setAction(RCDevice.ACTION_OUTGOING_CALL); intent.putExtra(RCDevice.EXTRA_DID, parsedUriString); intent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, true); startActivityForResult(intent, CONNECTION_REQUEST); globalPreferences.setExternalCallUri(""); } }
From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java
private void startActivityForAction(View view) { final IntentProvider intentProvider = (IntentProvider) view.getTag(); if (intentProvider != null) { final Intent intent = intentProvider.getIntent(mContext); // See IntentProvider.getCallDetailIntentProvider() for why this may be null. if (intent == null) return; // Intent to show call log details has no action, send also if we cannot handle call directly if (intent.getAction() == null || mPhoneNumberPickerActionListener == null) { DialerUtils.startActivityWithErrorToast(mContext, intent); return; }//from ww w . j a v a 2 s .c om if (Intent.ACTION_SENDTO.equals(intent.getAction())) { view.getContext().startActivity(intent); return; } Uri numberUri = intent.getData(); String number = numberUri.getSchemeSpecificPart(); mPhoneNumberPickerActionListener.onCallNumberDirectly(number); } }
From source file:gc.david.dfm.ui.MainActivity.java
/** * Handles a send intent with position data. * * @param intent Input intent with position data. *//*from w w w . j a v a 2s. c om*/ private void handleViewPositionIntent(final Intent intent) throws Exception { Mint.leaveBreadcrumb("MainActivity::handleViewPositionIntent"); final Uri uri = intent.getData(); Mint.addExtraData("queryParameter", uri.toString()); final String uriScheme = uri.getScheme(); if (uriScheme.equals("geo")) { final String schemeSpecificPart = uri.getSchemeSpecificPart(); final Matcher matcher = getMatcherForUri(schemeSpecificPart); if (matcher.find()) { if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) { if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label) setDestinationPosition(matcher); } else { // Manage geo:0,0?q=my+street+address String destination = Uri.decode(uri.getQuery()).replace('+', ' '); destination = destination.replace("q=", ""); // TODO check this ugly workaround new SearchPositionByName().execute(destination); mustShowPositionWhenComingFromOutside = true; } } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom setDestinationPosition(matcher); } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else if ((uriScheme.equals("http") || uriScheme.equals("https")) && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude final String queryParameter = uri.getQueryParameter("q"); if (queryParameter != null) { final Matcher matcher = getMatcherForUri(queryParameter); if (matcher.find()) { setDestinationPosition(matcher); } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Error al obtener las coordenadas. Matcher = " + matcher.toString()); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else { final NoSuchFieldException noSuchFieldException = new NoSuchFieldException( "Query sin parmetro q."); Mint.logException(noSuchFieldException); throw noSuchFieldException; } } else { final Exception exception = new Exception("Imposible tratar la query " + uri.toString()); Mint.logException(exception); throw exception; } }
From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { final ChooserHistory history = getHistory(); if ((mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) { // Build a reasonable intent filter, based on what matched. IntentFilter filter = new IntentFilter(); if (intent.getAction() != null) { filter.addAction(intent.getAction()); }/*from w w w . j a va 2 s. c o m*/ Set<String> categories = intent.getCategories(); if (categories != null) { for (String cat : categories) { filter.addCategory(cat); } } filter.addCategory(Intent.CATEGORY_DEFAULT); int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK; Uri data = intent.getData(); if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { String mimeType = intent.resolveType(this); if (mimeType != null) { try { filter.addDataType(mimeType); } catch (IntentFilter.MalformedMimeTypeException e) { Log.w("ResolverActivity", e); filter = null; } } } if (filter != null && data != null && data.getScheme() != null) { // We need the data specification if there was no type, // OR if the scheme is not one of our magical "file:" // or "content:" schemes (see IntentFilter for the reason). if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) { filter.addDataScheme(data.getScheme()); // Look through the resolved filter to determine which part // of it matched the original Intent. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); if (pIt != null) { String ssp = data.getSchemeSpecificPart(); while (ssp != null && pIt.hasNext()) { PatternMatcher p = pIt.next(); if (p.match(ssp)) { filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); break; } } } } Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); if (aIt != null) { while (aIt.hasNext()) { IntentFilter.AuthorityEntry a = aIt.next(); if (a.match(data) >= 0) { int port = a.getPort(); filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null); break; } } } Iterator<PatternMatcher> pIt = ri.filter.pathsIterator(); if (pIt != null) { String path = data.getPath(); while (path != null && pIt.hasNext()) { PatternMatcher p = pIt.next(); if (p.match(path)) { filter.addDataPath(p.getPath(), p.getType()); break; } } } } } if (filter != null) { ContentValues values = new ContentValues(3); values.put(HOST, mRequestedUri.getHost()); values.put(COMPONENT, intent.getComponent().flattenToString()); if (alwaysCheck) { values.put(PREFERRED, true); } values.put(LAST_CHOSEN, true); getContentResolver().insert(CONTENT_URI, values); history.add(intent.getComponent().getPackageName()); } } if (intent != null) { startActivity(intent); } history.save(this); }
From source file:com.android.server.telecom.testapps.TestConnectionService.java
@Override public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerAccount, final ConnectionRequest originalRequest) { final Uri handle = originalRequest.getAddress(); String number = originalRequest.getAddress().getSchemeSpecificPart(); log("call, number: " + number); // Crash on 555-DEAD to test call service crashing. if ("5550340".equals(number)) { throw new RuntimeException("Goodbye, cruel world."); }/*w w w . ja v a 2s . c om*/ Bundle extras = originalRequest.getExtras(); String gatewayPackage = extras.getString(TelecomManager.GATEWAY_PROVIDER_PACKAGE); Uri originalHandle = extras.getParcelable(TelecomManager.GATEWAY_ORIGINAL_ADDRESS); log("gateway package [" + gatewayPackage + "], original handle [" + originalHandle + "]"); final TestConnection connection = new TestConnection(false /* isIncoming */); setAddress(connection, handle); // If the number starts with 555, then we handle it ourselves. If not, then we // use a remote connection service. // TODO: Have a special phone number to test the account-picker dialog flow. if (number != null && number.startsWith("555")) { // Normally we would use the original request as is, but for testing purposes, we are // adding ".." to the end of the number to follow its path more easily through the logs. final ConnectionRequest request = new ConnectionRequest(originalRequest.getAccountHandle(), Uri.fromParts(handle.getScheme(), handle.getSchemeSpecificPart() + "..", ""), originalRequest.getExtras(), originalRequest.getVideoState()); connection.setVideoState(originalRequest.getVideoState()); /// M: only VideoCall addVideoProvider @{ if (originalRequest.getVideoState() == VideoProfile.STATE_BIDIRECTIONAL) { addVideoProvider(connection); } /// @} addCall(connection); connection.startOutgoing(); for (Connection c : getAllConnections()) { c.setOnHold(); } } else { log("Not a test number"); } return connection; }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Parse data pushed by {@link Intent}.//from w w w. j a va 2 s.c o m * * @param intent {@link Intent} */ private void parseIntent(final Intent intent) { final String action = intent.getAction(); Log.d(TAG, "launched with action: " + action); if (action == null) { return; } final Uri uri = intent.getData(); Log.i(TAG, "launched with uri: " + uri); if (uri != null && uri.toString().length() > 0) { // launched by clicking a sms: link, target number is in URI. final String scheme = uri.getScheme(); if (scheme != null) { if (scheme.equals("sms") || scheme.equals("smsto")) { final String s = uri.getSchemeSpecificPart(); this.parseSchemeSpecificPart(s); } else if (scheme.equals("content")) { this.parseThreadId(uri.getLastPathSegment()); } } } // check for extras String s = intent.getStringExtra("address"); if (!TextUtils.isEmpty(s)) { Log.d(TAG, "got address: " + s); this.lastTo = s; } s = intent.getStringExtra(Intent.EXTRA_TEXT); if (s == null) { Log.d(TAG, "got sms_body: " + s); s = intent.getStringExtra("sms_body"); } if (s == null) { final Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (stream != null) { Log.d(TAG, "got stream: " + stream); try { InputStream is = this.getContentResolver().openInputStream(stream); final BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line; while ((line = r.readLine()) != null) { sb.append(line + "\n"); } s = sb.toString().trim(); } catch (IOException e) { Log.e(TAG, "IO ERROR", e); } } } if (s != null) { Log.d(TAG, "set text: " + s); ((EditText) this.findViewById(R.id.text)).setText(s); this.lastMsg = s; } s = intent.getStringExtra(EXTRA_ERRORMESSAGE); if (s != null) { Log.e(TAG, "show error: " + s); Toast.makeText(this, s, Toast.LENGTH_LONG).show(); } final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); if (p.getBoolean(PREFS_AUTOSEND, true)) { s = intent.getStringExtra(WebSMS.EXTRA_AUTOSEND); Log.d(TAG, "try autosend.."); Log.d(TAG, "s: " + s); Log.d(TAG, "lastMsg: " + this.lastMsg); Log.d(TAG, "lastTo: " + this.lastTo); if (s != null && !TextUtils.isEmpty(this.lastMsg) && !TextUtils.isEmpty(this.lastTo)) { // all data is here Log.d(TAG, "do autosend"); if (p.getBoolean(PREFS_USE_CURRENT_CON, true)) { // push it to current active connector Log.d(TAG, "use current connector"); if (prefsConnectorSpec != null && prefsSubConnectorSpec != null) { Log.d(TAG, "autosend: call send()"); if (this.send(prefsConnectorSpec, prefsSubConnectorSpec) && !this.isFinishing()) { Log.d(TAG, "sent successfully"); this.finish(); } } } else { // show connector chooser Log.d(TAG, "show connector chooser"); final AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle(R.string.change_connector_); final ConnectorLabel[] items = this.getConnectorMenuItems(true /*isIncludePseudoConnectors*/); Log.d(TAG, "show #items: " + items.length); if (items.length > 0) { b.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final ConnectorLabel sel = items[which]; // save old selected connector final ConnectorSpec pr0 = prefsConnectorSpec; final SubConnectorSpec pr1 = prefsSubConnectorSpec; // switch to selected WebSMS.this.saveSelectedConnector(sel.getConnector(), sel.getSubConnector()); // send message boolean sent = false; Log.d(TAG, "autosend: call send()"); if (prefsConnectorSpec != null && prefsSubConnectorSpec != null) { sent = WebSMS.this.send(prefsConnectorSpec, prefsSubConnectorSpec); } // restore old connector WebSMS.this.saveSelectedConnector(pr0, pr1); // quit if (sent && !WebSMS.this.isFinishing()) { Log.d(TAG, "sent successfully"); WebSMS.this.finish(); } } }); b.setNegativeButton(android.R.string.cancel, null); b.show(); } } } } }
From source file:com.jtechme.apphub.FDroid.java
private void handleSearchOrAppViewIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); performSearch(query);//w w w .jav a2 s.co m return; } final Uri data = intent.getData(); if (data == null) { return; } final String scheme = data.getScheme(); final String path = data.getPath(); String packageName = null; String query = null; if (data.isHierarchical()) { final String host = data.getHost(); if (host == null) { return; } switch (host) { case "f-droid.org": if (path.startsWith("/repository/browse")) { // http://f-droid.org/repository/browse?fdfilter=search+query query = UriCompat.getQueryParameter(data, "fdfilter"); // http://f-droid.org/repository/browse?fdid=packageName packageName = UriCompat.getQueryParameter(data, "fdid"); } else if (path.startsWith("/app")) { // http://f-droid.org/app/packageName packageName = data.getLastPathSegment(); if ("app".equals(packageName)) { packageName = null; } } break; case "details": // market://details?id=app.id packageName = UriCompat.getQueryParameter(data, "id"); break; case "search": // market://search?q=query query = UriCompat.getQueryParameter(data, "q"); break; case "play.google.com": if (path.startsWith("/store/apps/details")) { // http://play.google.com/store/apps/details?id=app.id packageName = UriCompat.getQueryParameter(data, "id"); } else if (path.startsWith("/store/search")) { // http://play.google.com/store/search?q=foo query = UriCompat.getQueryParameter(data, "q"); } break; case "apps": case "amazon.com": case "www.amazon.com": // amzn://apps/android?p=app.id // http://amazon.com/gp/mas/dl/android?s=app.id packageName = UriCompat.getQueryParameter(data, "p"); query = UriCompat.getQueryParameter(data, "s"); break; } } else if ("fdroid.app".equals(scheme)) { // fdroid.app:app.id packageName = data.getSchemeSpecificPart(); } else if ("fdroid.search".equals(scheme)) { // fdroid.search:query query = data.getSchemeSpecificPart(); } if (!TextUtils.isEmpty(query)) { // an old format for querying via packageName if (query.startsWith("pname:")) packageName = query.split(":")[1]; // sometimes, search URLs include pub: or other things before the query string if (query.contains(":")) query = query.split(":")[1]; } if (!TextUtils.isEmpty(packageName)) { Utils.debugLog(TAG, "FDroid launched via app link for '" + packageName + "'"); Intent intentToInvoke = new Intent(this, AppDetails.class); intentToInvoke.putExtra(AppDetails.EXTRA_APPID, packageName); startActivity(intentToInvoke); } else if (!TextUtils.isEmpty(query)) { Utils.debugLog(TAG, "FDroid launched via search link for '" + query + "'"); performSearch(query); } }
From source file:org.fdroid.fdroid.FDroid.java
private void handleSearchOrAppViewIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); performSearch(query);/* w w w .ja v a2 s . c om*/ return; } final Uri data = intent.getData(); if (data == null) { return; } final String scheme = data.getScheme(); final String path = data.getPath(); String packageName = null; String query = null; if (data.isHierarchical()) { final String host = data.getHost(); if (host == null) { return; } switch (host) { case "f-droid.org": if (path.startsWith("/repository/browse")) { // http://f-droid.org/repository/browse?fdfilter=search+query query = UriCompat.getQueryParameter(data, "fdfilter"); // http://f-droid.org/repository/browse?fdid=packageName packageName = UriCompat.getQueryParameter(data, "fdid"); } else if (path.startsWith("/app")) { // http://f-droid.org/app/packageName packageName = data.getLastPathSegment(); if ("app".equals(packageName)) { packageName = null; } } break; case "details": // market://details?id=app.id packageName = UriCompat.getQueryParameter(data, "id"); break; case "search": // market://search?q=query query = UriCompat.getQueryParameter(data, "q"); break; case "play.google.com": if (path.startsWith("/store/apps/details")) { // http://play.google.com/store/apps/details?id=app.id packageName = UriCompat.getQueryParameter(data, "id"); } else if (path.startsWith("/store/search")) { // http://play.google.com/store/search?q=foo query = UriCompat.getQueryParameter(data, "q"); } break; case "apps": case "amazon.com": case "www.amazon.com": // amzn://apps/android?p=app.id // http://amazon.com/gp/mas/dl/android?s=app.id packageName = UriCompat.getQueryParameter(data, "p"); query = UriCompat.getQueryParameter(data, "s"); break; } } else if ("fdroid.app".equals(scheme)) { // fdroid.app:app.id packageName = data.getSchemeSpecificPart(); } else if ("fdroid.search".equals(scheme)) { // fdroid.search:query query = data.getSchemeSpecificPart(); } if (!TextUtils.isEmpty(query)) { // an old format for querying via packageName if (query.startsWith("pname:")) { packageName = query.split(":")[1]; } // sometimes, search URLs include pub: or other things before the query string if (query.contains(":")) { query = query.split(":")[1]; } } if (!TextUtils.isEmpty(packageName)) { Utils.debugLog(TAG, "FDroid launched via app link for '" + packageName + "'"); Intent intentToInvoke = new Intent(this, AppDetails.class); intentToInvoke.putExtra(AppDetails.EXTRA_APPID, packageName); startActivity(intentToInvoke); finish(); } else if (!TextUtils.isEmpty(query)) { Utils.debugLog(TAG, "FDroid launched via search link for '" + query + "'"); performSearch(query); } }
From source file:org.kontalk.ui.ComposeMessage.java
private Bundle processIntent(Bundle savedInstanceState) { Intent intent;/*from w ww. j av a 2s . co m*/ if (savedInstanceState != null) { mLostFocus = savedInstanceState.getBoolean("lostFocus"); Uri uri = savedInstanceState.getParcelable(Uri.class.getName()); if (uri == null) { Log.d(TAG, "restoring non-loaded conversation, aborting"); finish(); return null; } intent = new Intent(ACTION_VIEW_USERID, uri); } else { intent = getIntent(); } if (intent != null) { final String action = intent.getAction(); Bundle args = null; // view intent // view conversation - just threadId provided // view conversation - just userId provided if (Intent.ACTION_VIEW.equals(action) || ACTION_VIEW_CONVERSATION.equals(action) || ACTION_VIEW_USERID.equals(action)) { Uri uri = intent.getData(); // two-panes UI: start conversation list if (Kontalk.hasTwoPanesUI(this)) { Intent startIntent = new Intent(action, uri, getApplicationContext(), ConversationsActivity.class); startActivity(startIntent); // no need to go further finish(); return null; } // single-pane UI: start normally else { args = new Bundle(); args.putString("action", action); args.putParcelable("data", uri); args.putLong(EXTRA_MESSAGE, intent.getLongExtra(EXTRA_MESSAGE, -1)); args.putString(EXTRA_HIGHLIGHT, intent.getStringExtra(EXTRA_HIGHLIGHT)); args.putBoolean(EXTRA_CREATING_GROUP, intent.getBooleanExtra(EXTRA_CREATING_GROUP, false)); } } // send external content else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { sendIntent = intent; String mime = intent.getType(); Log.i(TAG, "sending data to someone: " + mime); chooseContact(); // onActivityResult will handle the rest return null; } // send to someone else if (Intent.ACTION_SENDTO.equals(action)) { try { Uri uri = intent.getData(); // a phone number should come here... String number = NumberValidator.fixNumber(this, uri.getSchemeSpecificPart(), Authenticator.getDefaultAccountName(this), 0); // compute hash and open conversation String jid = XMPPUtils.createLocalJID(this, MessageUtils.sha1(number)); // two-panes UI: start conversation list if (Kontalk.hasTwoPanesUI(this)) { Intent startIntent = new Intent(getApplicationContext(), ConversationsActivity.class); startIntent.setAction(ACTION_VIEW_USERID); startIntent.setData(Threads.getUri(jid)); startActivity(startIntent); // no need to go further finish(); return null; } // single-pane UI: start normally else { args = new Bundle(); args.putString("action", ComposeMessage.ACTION_VIEW_USERID); args.putParcelable("data", Threads.getUri(jid)); args.putString("number", number); } } catch (Exception e) { Log.e(TAG, "invalid intent", e); finish(); } } return args; } return null; }