Example usage for android.net Uri getHost

List of usage examples for android.net Uri getHost

Introduction

In this page you can find the example usage for android.net Uri getHost.

Prototype

@Nullable
public abstract String getHost();

Source Link

Document

Gets the encoded host from the authority for this URI.

Usage

From source file:com.cullaboration.userhookdemo.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);//  w  w w  .j  a  v  a 2  s  .c o m

    // check for deep link

    if (intent.getAction().equals(Intent.ACTION_VIEW)) {
        Uri uri = intent.getData();

        // respond to deep link for url, userhookdemo://product
        if (uri.getHost().equals("product")) {
            Intent newIntent = new Intent(MainActivity.this, PurchaseActivity.class);
            startActivity(newIntent);
        }

    }
}

From source file:com.cyberprism.libin.artourist.ARActivity.java

@Override
public ArchitectView.ArchitectUrlListener getUrlListener() {
    return new ArchitectView.ArchitectUrlListener() {

        @Override/* w  w  w .  j  a va  2 s  .  c om*/
        public boolean urlWasInvoked(String uriString) {
            Uri invokedUri = Uri.parse(uriString);

            // pressed "More" button on POI-detail panel
            if ("markerselected".equalsIgnoreCase(invokedUri.getHost())) {
                final Intent poiDetailIntent = new Intent(ARActivity.this, SamplePoiDetailActivity.class);
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_ID,
                        String.valueOf(invokedUri.getQueryParameter("id")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_TITILE,
                        String.valueOf(invokedUri.getQueryParameter("title")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_DESCR,
                        String.valueOf(invokedUri.getQueryParameter("description")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.LATITUDE_KEY,
                        String.valueOf(invokedUri.getQueryParameter("latitude")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.LONGITUDE_KEY,
                        String.valueOf(invokedUri.getQueryParameter("longitude")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.IMAGE_KEY,
                        String.valueOf(invokedUri.getQueryParameter("image")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.IMAGE_RATING,
                        String.valueOf(invokedUri.getQueryParameter("rating")));
                ARActivity.this.startActivity(poiDetailIntent);

                Log.d("IMAGE", String.valueOf(invokedUri.getQueryParameter("image")));

                return true;
            }

            // pressed snapshot button. check if host is button to fetch e.g. 'architectsdk://button?action=captureScreen', you may add more checks if more buttons are used inside AR scene
            else if ("button".equalsIgnoreCase(invokedUri.getHost())) {
                ARActivity.this.architectView.captureScreen(
                        ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW,
                        new ArchitectView.CaptureScreenCallback() {

                            @Override
                            public void onScreenCaptured(final Bitmap screenCapture) {
                                if (ContextCompat.checkSelfPermission(ARActivity.this,
                                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                                    ARActivity.this.screenCapture = screenCapture;
                                    ActivityCompat.requestPermissions(ARActivity.this,
                                            new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                            WIKITUDE_PERMISSIONS_REQUEST_EXTERNAL_STORAGE);
                                } else {
                                    ARActivity.this.saveScreenCaptureToExternalStorage(screenCapture);
                                }
                            }
                        });
            }
            return true;
        }
    };
}

From source file:com.rafamaya.imagesearch.DataLayerListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents);
    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.close();/*w w  w.  jav a 2  s.c  o  m*/
    if (!mGoogleApiClient.isConnected()) {
        ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS);
        if (!connectionResult.isSuccess()) {
            Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient.");
            return;
        }
    }

    // Loop through the events and send a message back to the node that created the data item.
    for (DataEvent event : events) {
        Uri uri = event.getDataItem().getUri();
        String path = uri.getPath();
        if (COUNT_PATH.equals(path)) {
            // Get the node id of the node that created the data item from the host portion of
            // the uri.
            String nodeId = uri.getHost();
            // Set the data of the message to be the bytes of the Uri.
            byte[] payload = uri.toString().getBytes();

            // Send the rpc
            Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, DATA_ITEM_RECEIVED_PATH, payload);
        }
    }
}

From source file:at.bitfire.davdroid.ui.setup.LoginCredentialsFragment.java

protected LoginCredentials validateLoginData() {
    if (radioUseEmail.isChecked()) {
        URI uri = null;/*w w  w  .jav a 2  s  .c om*/
        boolean valid = true;

        String email = editEmailAddress.getText().toString();
        if (!email.matches(".+@.+")) {
            editEmailAddress.setError(getString(R.string.login_email_address_error));
            valid = false;
        } else
            try {
                uri = new URI("mailto", email, null);
            } catch (URISyntaxException e) {
                editEmailAddress.setError(e.getLocalizedMessage());
                valid = false;
            }

        String password = editEmailPassword.getText().toString();
        if (password.isEmpty()) {
            editEmailPassword.setError(getString(R.string.login_password_required));
            valid = false;
        }

        return valid ? new LoginCredentials(uri, email, password) : null;

    } else if (radioUseURL.isChecked()) {
        URI uri = null;
        boolean valid = true;

        Uri baseUrl = Uri.parse(editBaseURL.getText().toString());
        String scheme = baseUrl.getScheme();
        if ("https".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) {
            String host = baseUrl.getHost();
            if (StringUtils.isEmpty(host)) {
                editBaseURL.setError(getString(R.string.login_url_host_name_required));
                valid = false;
            } else
                try {
                    host = IDN.toASCII(host);
                } catch (IllegalArgumentException e) {
                    Constants.log.log(Level.WARNING, "Host name not conforming to RFC 3490", e);
                }

            String path = baseUrl.getEncodedPath();
            int port = baseUrl.getPort();
            try {
                uri = new URI(baseUrl.getScheme(), null, host, port, path, null, null);
            } catch (URISyntaxException e) {
                editBaseURL.setError(e.getLocalizedMessage());
                valid = false;
            }
        } else {
            editBaseURL.setError(getString(R.string.login_url_must_be_http_or_https));
            valid = false;
        }

        String userName = editUserName.getText().toString();
        if (userName.isEmpty()) {
            editUserName.setError(getString(R.string.login_user_name_required));
            valid = false;
        }

        String password = editUrlPassword.getText().toString();
        if (password.isEmpty()) {
            editUrlPassword.setError(getString(R.string.login_password_required));
            valid = false;
        }

        return valid ? new LoginCredentials(uri, userName, password) : null;
    }

    return null;
}

From source file:de.schildbach.wallet.ui.backup.BackupWalletDialogFragment.java

private @Nullable String uriToTarget(final Uri uri) {
    if (!uri.getScheme().equals("content"))
        return null;
    final String host = uri.getHost();
    if ("com.google.android.apps.docs.storage".equals(host))
        return "Google Drive";
    if ("com.android.providers.downloads.documents".equals(host))
        return "internal storage";
    return null;/* w ww  .jav  a2 s.c  o m*/
}

From source file:me.xingrz.prox.tcp.TcpProxySession.java

public void setDestination(Uri proxy) {
    if (proxy.getScheme().equals(AutoConfigManager.PROXY_TYPE_HTTP)) {
        outgoingTunnel.setProxy(//  w ww  .  j av a2 s  . co  m
                new HttpConnectHandler(outgoingTunnel, getRemoteAddress().getHostAddress(), getRemotePort()));

        logger.v("Use HTTP proxy %s:%d", proxy.getHost(), proxy.getPort());

        destination = new InetSocketAddress(proxy.getHost(), proxy.getPort());
    } else {
        logger.v("Unsupported proxy scheme %s, ignored", proxy.getScheme());
    }
}

From source file:com.facebook.android.GraphExplorer.java

protected void processIntent(Intent incomingIntent) {
    Uri intentUri = incomingIntent.getData();
    if (intentUri == null) {
        return;//from  w  ww .  j  a v  a 2s  . c o  m
    }
    String objectID = intentUri.getHost();
    mInputId.setText(objectID);
    mSubmitButton.performClick();
}

From source file:com.wipro.sa349342.wmar.SampleCamActivity.java

@Override
public ArchitectUrlListener getUrlListener() {
    return new ArchitectUrlListener() {

        @Override/*from  w w w .  jav a2s.  c o m*/
        public boolean urlWasInvoked(String uriString) {
            Uri invokedUri = Uri.parse(uriString);

            // pressed "More" button on POI-detail panel
            if ("markerselected".equalsIgnoreCase(invokedUri.getHost())) {
                final Intent poiDetailIntent = new Intent(SampleCamActivity.this,
                        SamplePoiDetailActivity.class);
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_ID,
                        String.valueOf(invokedUri.getQueryParameter("id")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_TITILE,
                        String.valueOf(invokedUri.getQueryParameter("title")));
                poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_DESCR,
                        String.valueOf(invokedUri.getQueryParameter("description")));
                SampleCamActivity.this.startActivity(poiDetailIntent);
                return true;
            }
            // pressed "Models " button on POI-detail panel
            else if ("showModels".equalsIgnoreCase(invokedUri.getHost())) {
                final Intent intentModelOverlays = new Intent(getBaseContext(), SampleCamActivity.class);

                intentModelOverlays.putExtra("activityTitle", "1.3 Extended Tracking");
                intentModelOverlays.putExtra("activityArchitectWorldUrl",
                        "samples/1_Client$Recognition_3_Extended$Tracking/index.html");
                intentModelOverlays.putExtra("activityIr", true);
                intentModelOverlays.putExtra("activityGeo", false);
                intentModelOverlays.putExtra("showMap", false);

                startActivity(intentModelOverlays);
                return true;
            }
            // pressed "Scan " button on POI-detail panel
            else if ("scan".equalsIgnoreCase(invokedUri.getHost())) {

                String equipCategory = String.valueOf(invokedUri.getQueryParameter("category"));

                if (equipCategory.equalsIgnoreCase("MT")) {
                    final Intent intentScan = new Intent(getBaseContext(), BarcodeAndQRcodeScanActivity.class);
                    intentScan.putExtra("meterEqip", true);
                    startActivity(intentScan);

                } else {
                    final Intent intentScan = new Intent(getBaseContext(), BarcodeAndQRcodeScanActivity.class);
                    intentScan.putExtra("meterEqip", false);
                    startActivity(intentScan);

                }

                return true;
            } else if ("showMap".equalsIgnoreCase(invokedUri.getHost())) {

                View mapFrag = findViewById(R.id.map);

                if (Boolean.valueOf(invokedUri.getQueryParameter("mapON"))) {

                    mapFrag.setVisibility(View.VISIBLE);
                } else {

                    mapFrag.setVisibility(View.GONE);
                }

                return true;
            }

            // pressed snapshot button. check if host is button to fetch e.g. 'architectsdk://button?action=captureScreen', you may add more checks if more buttons are used inside AR scene
            else if ("button".equalsIgnoreCase(invokedUri.getHost())) {
                SampleCamActivity.this.architectView.captureScreen(
                        ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW,
                        new CaptureScreenCallback() {

                            @Override
                            public void onScreenCaptured(final Bitmap screenCapture) {
                                if (ContextCompat.checkSelfPermission(SampleCamActivity.this,
                                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                                    SampleCamActivity.this.screenCapture = screenCapture;
                                    ActivityCompat.requestPermissions(SampleCamActivity.this,
                                            new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                            WIKITUDE_PERMISSIONS_REQUEST_EXTERNAL_STORAGE);
                                } else {
                                    SampleCamActivity.this.saveScreenCaptureToExternalStorage(screenCapture);
                                }
                            }
                        });
            }
            return true;
        }
    };
}

From source file:com.thanhle.englishvocabulary.DataLayerListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "onDataChanged: " + dataEvents);
    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.close();//from   w w w .j a  v a  2s  .  co  m
    if (!mGoogleApiClient.isConnected()) {
        ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS);
        if (!connectionResult.isSuccess()) {
            Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient.");
            return;
        }
    }

    // Loop through the events and send a message back to the node that
    // created the data item.
    for (DataEvent event : events) {
        Uri uri = event.getDataItem().getUri();
        String path = uri.getPath();
        if (WearConsts.SYNC_PATH.equals(path)) {
            // Get the node id of the node that created the data item from
            // the host portion of
            // the uri.
            String nodeId = uri.getHost();
            // Set the data of the message to be the bytes of the Uri.
            byte[] payload = uri.toString().getBytes();

            // Send the message back
            Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, WearConsts.DATA_ITEM_RECEIVED_PATH,
                    payload);

            // get DataMap item
            DataMapItem dataItem = DataMapItem.fromDataItem(event.getDataItem());
            String library = dataItem.getDataMap().getString(WearConsts.LIBRARY_KEY);
            ArrayList<String> cards = dataItem.getDataMap().getStringArrayList(WearConsts.CARDS_KEY);
            if (cards != null) {
                Log.d(TAG, "library: " + library + ", cards: " + cards.size());
                // convert to ArrayList CardTable
                ArrayList<CardTable> r = new ArrayList<CardTable>();
                for (String cardText : cards) {
                    r.add(new CardTable(cardText));
                }
                if (r.size() > 0) {
                    // clear old database
                    database.clearListCards(library);
                    // add all card list
                    database.insertCard(r);
                    Log.d(TAG, "sync card success");
                }

                // Broadcast message to wearable activity for display
                Intent messageIntent = new Intent();
                messageIntent.setAction(WearConsts.ACTION_DATA_FORWARDED);
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
            }
        }
    }
}

From source file:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java

/**
 * Creates the base add/edit bookmark fragment based on the intent passed to this activity.
 *
 * @return The appropriate fragment based on the intent parameters.
 *///from ww  w . ja  v  a2s. co m
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private AddEditBookmarkFragment generateBaseFragment() {
    if (getIntent() == null) {
        throw new IllegalArgumentException("intent can not be null");
    }
    Intent intent = getIntent();
    Uri intentUri = intent.getData();

    Long bookmarkId = null;
    boolean isFolder = false;
    AddEditBookmarkFragment addEditFragment;
    if (intentUri != null && intentUri.getHost().equals("editbookmark")) {
        isFolder = intentUri.getBooleanQueryParameter(BOOKMARK_IS_FOLDER_URI_PARAM, false);
        String bookmarkIdParam = intentUri.getQueryParameter(BOOKMARK_ID_URI_PARAM);
        if (bookmarkIdParam != null)
            bookmarkId = Long.parseLong(bookmarkIdParam);
        addEditFragment = AddEditBookmarkFragment.newEditInstance(isFolder, bookmarkId);
    } else {
        Bundle extras = intent.getExtras();
        String url = null;
        String name = null;
        if (extras != null) {
            isFolder = extras.getBoolean(BOOKMARK_INTENT_IS_FOLDER, false);

            if (extras.containsKey(BOOKMARK_INTENT_TITLE)) {
                name = extras.getString(BOOKMARK_INTENT_TITLE);
            }
            if (extras.containsKey(BOOKMARK_INTENT_URL)) {
                url = extras.getString(BOOKMARK_INTENT_URL);
                url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
            }
            if (extras.containsKey(BOOKMARK_INTENT_ID)) {
                bookmarkId = extras.getLong(BOOKMARK_INTENT_ID);
            }
        }
        addEditFragment = AddEditBookmarkFragment.newInstance(isFolder, bookmarkId, name, url);
    }
    setActionListenerOnAddEdit(addEditFragment);
    return addEditFragment;
}