Example usage for android.net Uri getQueryParameter

List of usage examples for android.net Uri getQueryParameter

Introduction

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

Prototype

@Nullable
public String getQueryParameter(String key) 

Source Link

Document

Searches the query string for the first value with the given key.

Usage

From source file:io.github.hidroh.materialistic.accounts.UserServicesClient.java

private Throwable buildException(Uri uri) {
    switch (uri.getPath()) {
    case ITEM_PATH:
        UserServices.Exception exception = new UserServices.Exception(R.string.item_exist);
        String itemId = uri.getQueryParameter(ITEM_PARAM_ID);
        if (!TextUtils.isEmpty(itemId)) {
            exception.data = AppUtils.createItemUri(itemId);
        }/*from w w w  .  j ava2 s  .  com*/
        return exception;
    default:
        return new IOException();
    }
}

From source file:de.knufficast.flattr.FlattrApi.java

/**
 * Inform this client of an OAuth response.
 * //from  w  ww. ja v a 2  s .  com
 * @param data
 *          the URI of the OAuth response
 */
public void setOauthResponse(final String data) {
    runOnThread(new Runnable() {
        @Override
        public void run() {
            Uri uri = Uri.parse(data);
            FlattrConfiguration config = App.get().getConfiguration().getFlattrConfig();
            config.setFlattrStatus(FlattrStatus.AUTHENTICATING);
            if (uri.getQueryParameter("code") != null) {
                config.setAuthCode(uri.getQueryParameter("code"));
                login();
            } else {
                config.setFlattrStatus(FlattrStatus.ERROR);
            }
        }
    });
}

From source file:net.wequick.small.webkit.WebActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int theme = Small.getWebActivityTheme();
    if (theme != 0)
        setTheme(theme);/*w  w w. ja v  a  2 s .  co  m*/

    boolean fullscreen = false;
    CharSequence queryTitle;
    Uri uri = Small.getUri(this);
    if (uri != null) {
        String param = uri.getQueryParameter("_fullscreen");
        if (param != null) {
            fullscreen = param.equals("1");
        }
        queryTitle = uri.getQueryParameter("_title");
        if (queryTitle != null) {
            super.setTitle(queryTitle);
            mCanSetTitle = false;
        }
    }

    // Init actionBar
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        if (fullscreen) {
            actionBar.hide();
        } else {
            actionBar.show();
            Activity parent = getParent();
            if (parent == null) { // If is created by a LocalActivityManager, parent is not null
                actionBar.setDisplayHomeAsUpEnabled(true);
            }
        }
    }
    mFullscreen = fullscreen;

    // Initialize content wrapper
    RelativeLayout wrapper = new RelativeLayout(this);
    wrapper.setGravity(Gravity.CENTER);
    setContentView(wrapper);

    // Initialize webView
    mWebView = new WebView(this);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    wrapper.addView(mWebView, 0, layoutParams);

    // Try to load title from cache
    mUrl = getIntent().getStringExtra("url");
    if (mCanSetTitle) {
        CharSequence title = getCacheTitle(mUrl);
        if (title != null) {
            super.setTitle(title);
        }
    }
}

From source file:de.janrenz.app.mediathek.ArdMediathekProvider.java

@Override
public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) {
    String url = "";
    String queryparam = uri.getQueryParameter("timestamp");
    ;/*from   w w  w .j  ava 2  s .  co  m*/
    Integer timestamp = null;
    if (queryparam == null) {
        Date dt = new Date();
        timestamp = dt.getSeconds();
    } else {

        timestamp = Integer.parseInt(queryparam);
    }

    String queryparammethod = uri.getQueryParameter("method");
    if (queryparammethod == null) {
        queryparammethod = "list";
        url = "http://m-service.daserste.de/appservice/1.4.2/video/list/" + timestamp
                + "?func=getVideoList&unixTimestamp=" + timestamp;
    } else if (queryparammethod.equalsIgnoreCase("search")) {
        // url = /appservice/1.4.1/search/heiter/0/25?func=getSearchResultList&searchPattern=heiter&searchOffset=0&searchLength=25
        String searchQuery = uri.getQueryParameter("query");
        //!TODO make this url safe
        url = "http://m-service.daserste.de/appservice/1.4.2/search/" + URLEncoder.encode(searchQuery)
                + "/0/50?func=getSearchResultList&searchPattern=" + URLEncoder.encode(searchQuery)
                + "&searchOffset=0&searchLength=50";
    } else if (queryparammethod.equalsIgnoreCase("broadcast")) {
        url = "http://m-service.daserste.de/appservice/1.4.2/broadcast/current/" + timestamp
                + "?func=getCurrentBroadcast&unixTimestamp=" + timestamp;
    } else {
        // oh oh
    }
    String queryparamReload = uri.getQueryParameter("reload");
    String queryExtReload = "";
    if (queryparamReload != null) {
        queryExtReload = "&reload=" + Math.random();
    }

    String result = "";
    result = readJSONFeed(url);
    MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "title", "subtitle", "image", "extId",
            "startTime", "startTimeAsTimestamp", "isLive" });
    if (result == "") {
        return cursor;
    }

    if (queryparammethod.equalsIgnoreCase("broadcast")) {
        cursor = (MatrixCursor) processResultForBroadcast(result);
    } else if (queryparammethod.equalsIgnoreCase("search")) {
        cursor = (MatrixCursor) processResultForList(result, true);
    } else {
        Boolean orderParam = false;
        try {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
            Boolean reverse = sharedPref.getBoolean(SettingsActivity.REVERSE_LIST_ORDER, false);

            //reverse is menat by user perspective here, by default its false
            if (reverse == true) {
                orderParam = true;
            }
        } catch (Exception e) {
            // use the default if we cant fetch it
        }
        //Log.e("order Param", orderParam.toString());
        cursor = (MatrixCursor) processResultForList(result, orderParam);
    }

    return (Cursor) cursor;
}

From source file:de.yaacc.upnp.server.YaaccHttpService.java

@Override
protected void doService(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {
    Log.d(getClass().getName(), "Processing HTTP request: " + request.getRequestLine().toString());

    // Extract what we need from the HTTP httpRequest
    String requestMethod = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);

    // Only accept HTTP-GET
    if (!requestMethod.equals("GET") && !requestMethod.equals("HEAD")) {
        Log.d(getClass().getName(), "HTTP request isn't GET or HEAD stop! Method was: " + requestMethod);
        throw new MethodNotSupportedException(requestMethod + " method not supported");
    }// w ww.  j av a  2 s.co  m

    Uri requestUri = Uri.parse(request.getRequestLine().getUri());
    String contentId = requestUri.getQueryParameter("id");
    contentId = contentId == null ? "" : contentId;
    String albumId = requestUri.getQueryParameter("album");
    albumId = albumId == null ? "" : albumId;
    String thumbId = requestUri.getQueryParameter("thumb");
    thumbId = thumbId == null ? "" : thumbId;
    if (contentId.equals("") && albumId.equals("") && thumbId.equals("")) {
        response.setStatusCode(HttpStatus.SC_FORBIDDEN);
        StringEntity entity = new StringEntity("<html><body><h1>Access denied</h1></body></html>", "UTF-8");
        response.setEntity(entity);
        Log.d(getClass().getName(), "end doService: Access denied");
        return;
    }
    ContentHolder contentHolder = null;
    if (!contentId.equals("")) {
        contentHolder = lookupContent(contentId);

    } else if (!albumId.equals("")) {
        contentHolder = lookupAlbumArt(albumId);
    } else if (!thumbId.equals("")) {
        contentHolder = lookupThumbnail(thumbId);
    }
    if (contentHolder == null) {
        // tricky but works
        Log.d(getClass().getName(), "Resource with id " + contentId + albumId + thumbId + " not found");
        response.setStatusCode(HttpStatus.SC_NOT_FOUND);
        StringEntity entity = new StringEntity("<html><body><h1>Resource with id " + contentId + albumId
                + thumbId + " not found</h1></body></html>", "UTF-8");
        response.setEntity(entity);
    } else {

        response.setStatusCode(HttpStatus.SC_OK);
        response.setEntity(contentHolder.getHttpEntity());
    }
    Log.d(getClass().getName(), "end doService: ");
}

From source file:com.example.rps.MainActivity.java

private int getAppLinkGesture(Intent intent) {
    Uri targetURI = AppLinks.getTargetUrlFromInboundIntent(this, intent);
    if (targetURI == null) {
        return INVALID_CHOICE;
    }/*from  w w  w .  ja v  a2  s . co m*/
    String gesture = targetURI.getQueryParameter("gesture");
    if (gesture != null) {
        if (gesture.equalsIgnoreCase(getString(R.string.rock))) {
            return RpsGameUtils.ROCK;
        } else if (gesture.equalsIgnoreCase(getString(R.string.paper))) {
            return RpsGameUtils.PAPER;
        } else if (gesture.equalsIgnoreCase(getString(R.string.scissors))) {
            return RpsGameUtils.SCISSORS;
        }
    }
    return INVALID_CHOICE;
}

From source file:com.gh4a.activities.SearchActivity.java

@Override
public void onItemClick(Object item) {
    if (item instanceof Repository) {
        Repository repository = (Repository) item;
        startActivity(IntentUtils.getRepoActivityIntent(this, repository.getOwner().getLogin(),
                repository.getName(), null));
    } else if (item instanceof CodeSearchResult) {
        CodeSearchResult result = (CodeSearchResult) item;
        Repository repo = result.getRepository();
        Uri uri = Uri.parse(result.getUrl());
        String ref = uri.getQueryParameter("ref");
        startActivity(IntentUtils.getFileViewerActivityIntent(this, repo.getOwner().getLogin(), repo.getName(),
                ref, result.getPath()));
    } else {/*from ww w .j  a v a 2  s .co m*/
        SearchUser user = (SearchUser) item;
        startActivity(IntentUtils.getUserActivityIntent(this, user.getLogin(), user.getName()));
    }
}

From source file:com.dawsonloudon.videoplayer.VideoPlayer.java

private void playVideo(String url) throws IOException {
    if (url.contains("bit.ly/") || url.contains("goo.gl/") || url.contains("tinyurl.com/")
            || url.contains("youtu.be/")) {
        //support for google / bitly / tinyurl / youtube shortens
        URLConnection con = new URL(url).openConnection();
        con.connect();/*from  w  w  w.  jav  a  2  s . com*/
        InputStream is = con.getInputStream();
        //new redirected url
        url = con.getURL().toString();
        is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        if (isYouTubeInstalled()) {
            intent = new Intent(Intent.ACTION_VIEW, uri);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
        }
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);
        if (!fp.exists()) {
            this.copy(filepath, filename);
        }

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}

From source file:org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java

public SignInResult getSignInResult(final String origOAuthOrizationUrlString, final String username,
        final String password) throws IOException {
    if (isEmpty(origOAuthOrizationUrlString) || isEmpty(username) || isEmpty(password))
        throw new IllegalArgumentException();
    try {/* w  ww  . j av  a  2s.c o m*/
        final String oauthOrizationUrlString = Utils.replaceAPIUri(sharedPrefs, origOAuthOrizationUrlString);
        final String hostHeader = Utils.getCustomAPIHostHeader(sharedPrefs, origOAuthOrizationUrlString);
        final Uri authorizationUri = Uri.parse(oauthOrizationUrlString);
        final String oauthToken = authorizationUri.getQueryParameter(QUERY_PARAM_OAUTH_TOKEN);
        if (isEmpty(oauthToken))
            throw new InvalidOAuthTokenException();
        final HttpGet getAuthenticityToken = new HttpGet(oauthOrizationUrlString);
        if (hostHeader != null) {
            getAuthenticityToken.setHeader("Host", hostHeader);
        }
        if (Utils.isDebugBuild()) {
            Log.d(LOGTAG, String.format("Read authenticity token from %s", oauthOrizationUrlString));
        }
        final String authenticityToken = httpClient.execute(getAuthenticityToken,
                new GetAuthenticityTokenHandler());
        if (isEmpty(authenticityToken))
            throw new AuthenticityTokenException();
        final ArrayList<NameValuePair> getOAuthResultParams = new ArrayList<NameValuePair>();
        getOAuthResultParams.add(new BasicNameValuePair("authenticity_token", authenticityToken));
        getOAuthResultParams.add(new BasicNameValuePair("oauth_token", oauthToken));
        getOAuthResultParams.add(new BasicNameValuePair("session[username_or_email]", username));
        getOAuthResultParams.add(new BasicNameValuePair("session[password]", password));
        final UrlEncodedFormEntity getOAuthResultEntity = new UrlEncodedFormEntity(getOAuthResultParams,
                HTTP.UTF_8);
        final HttpPost getOAuthAuthorization = new HttpPost(
                Utils.replaceAPIUri(sharedPrefs, TWITTER_OAUTH_AUTHORIZATION_URL));
        getOAuthAuthorization.setEntity(getOAuthResultEntity);
        if (hostHeader != null) {
            getOAuthAuthorization.setHeader("Host", hostHeader);
        }
        return httpClient.execute(getOAuthAuthorization, new GetOAuthAuthorizationHandler());
    } catch (final NullPointerException e) {
        throw new AuthenticationException(e);
    }
}

From source file:cgeo.geocaching.connector.oc.OCApiConnector.java

/**
 * get the OC1234 geocode from an internal cache id, for URLs like host.tld/viewcache.php?cacheid
 *///  w ww. ja  v  a2 s  . c o  m
@Nullable
protected String getGeocodeFromCacheId(final String url, final String host) {
    final Uri uri = Uri.parse(url);
    if (!StringUtils.containsIgnoreCase(uri.getHost(), host)) {
        return null;
    }

    // host.tld/viewcache.php?cacheid=cacheid
    final String id = uri.getPath().startsWith("/viewcache.php") ? uri.getQueryParameter("cacheid") : "";
    if (StringUtils.isNotBlank(id)) {
        final String geocode = Maybe.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                final String normalizedUrl = StringUtils.replaceIgnoreCase(url, getShortHost(), getShortHost());
                return OkapiClient.getGeocodeByUrl(OCApiConnector.this, normalizedUrl);
            }
        }).subscribeOn(AndroidRxUtils.networkScheduler).blockingGet();

        if (geocode != null && canHandle(geocode)) {
            return geocode;
        }
    }
    return null;
}