Example usage for android.net Uri toString

List of usage examples for android.net Uri toString

Introduction

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

Prototype

public abstract String toString();

Source Link

Document

Returns the encoded string representation of this URI.

Usage

From source file:com.owncloud.android.authenticator.AuthenticationRunnable.java

@Override
public void run() {
    Uri uri;
    uri = Uri.parse(mUrl.toString());/*w  w  w. ja  va  2s  .com*/
    WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(uri, mUsername, mPassword, mContext);
    int login_result = wdc.tryToLogin();
    switch (login_result) {
    case HttpStatus.SC_OK:
        postResult(true, uri.toString());
        break;
    case HttpStatus.SC_UNAUTHORIZED:
        postResult(false, mContext.getString(R.string.auth_unauthorized));
        break;
    case HttpStatus.SC_NOT_FOUND:
        postResult(false, mContext.getString(R.string.auth_not_found));
        break;
    default:
        postResult(false, String.format(mContext.getString(R.string.auth_internal), login_result));
    }
}

From source file:com.example.android.popularmoviesist2.data.FetchDetailMovieTask.java

@Override
protected String[] doInBackground(String... params) {

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;
    movieId = params[0];/* w  w  w  .  ja  v a2s . c  om*/

    String moviesJsonStr = null;

    final String MOVIE_REVIEW_URL = "http://api.themoviedb.org/3/movie/" + movieId + "/reviews";

    final String APIKEY_PARAM = "api_key";

    try {
        Uri builtUri = Uri.parse(MOVIE_REVIEW_URL).buildUpon()
                .appendQueryParameter(APIKEY_PARAM, BuildConfig.OPEN_TMDB_MAP_API_KEY).build();

        URL url = new URL(builtUri.toString());

        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        // Read the input stream into a String
        InputStream inputStream = urlConnection.getInputStream();
        StringBuffer buffer = new StringBuffer();
        if (inputStream == null) {
            return null;
        }

        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            return null;
        }

        moviesJsonStr = buffer.toString();

        //Log.v(LOG_TAG, "Movies string: " + moviesJsonStr);
        return getMoviesDataFromJson(moviesJsonStr);

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        return null;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                Log.e(LOG_TAG, "Error closing stream", e);
            }
        }
    }

    return null;
}

From source file:org.mobisocial.corral.ContentCorral.java

public static String getWebappCacheName(Uri webapp) {
    return Util.convertToHex(Util.sha256(webapp.toString().getBytes())).substring(0, 10);
}

From source file:org.blanco.techmun.android.cproviders.TechMunContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    //HttpGet req = new HttpGet(MESAS_REST_SERVICE_BSAE_URI);
    if (uri.toString().matches(MESA_CONTENT_EVENTOS_PETITION_REG_EXP)) {
        return getEventosCursorForUri(uri);
    } else if (uri.toString().matches(MESA_CONTENT_COMENTARIOS_PETITION_REG_EXP)) {
        return getComentariosCursorForUri(uri, selection);
    } else if (uri.toString().matches(MESA_CONTENT_MENSAJES_PETITION_REG_EXP)) {
        return getMensajesCursorForUri(uri);
    } else if (uri.toString().matches(CONTENT_BASE_URI)) {
        return getMesasCursorForUri(uri);
    }/*  ww w  .j a  va  2 s.c o  m*/
    return null;
}

From source file:com.example.android.popularmoviesist2.data.FetchTrailerMovieTask.java

@Override
protected String[] doInBackground(String... params) {

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;
    movieId = params[0];//from ww w . j ava  2 s .  c o  m

    String moviesJsonStr = null;

    final String MOVIE_VIDEO_URL = "http://api.themoviedb.org/3/movie/" + movieId + "/videos";

    final String APIKEY_PARAM = "api_key";

    try {
        Uri builtUri = Uri.parse(MOVIE_VIDEO_URL).buildUpon()
                .appendQueryParameter(APIKEY_PARAM, BuildConfig.OPEN_TMDB_MAP_API_KEY).build();

        URL url = new URL(builtUri.toString());

        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        InputStream inputStream = urlConnection.getInputStream();
        StringBuffer buffer = new StringBuffer();
        if (inputStream == null) {
            return null;
        }

        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            return null;
        }

        moviesJsonStr = buffer.toString();
        return getMoviesDataFromJson(moviesJsonStr);

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        return null;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                Log.e(LOG_TAG, "Error closing stream", e);
            }
        }
    }

    return null;
}

From source file:me.xingrz.finder.EntriesActivity.java

public void safelyStartViewActivity(Uri uri, String mime) {
    Intent intent = intentToView(uri, mime);

    try {/*from  ww w. j  av  a  2 s  .  c  o  m*/
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.d(TAG, "Failed to start viewer activity for uri " + uri.toString(), e);
        Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
    }

    overridePendingTransitionForBuiltInViewer(intent);
}

From source file:com.example.android.popularmoviesist2.data.FetchMovieTask.java

@Override
protected String[] doInBackground(String... params) {

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;
    orderBy = params[0];// w  w  w.  ja va2  s . c o  m

    String moviesJsonStr = null;

    try {

        final String MOVIE_BASE_URL = "http://api.themoviedb.org/3/movie/" + orderBy;
        final String APIKEY_PARAM = "api_key";

        Uri builtUri = Uri.parse(MOVIE_BASE_URL).buildUpon()
                .appendQueryParameter(APIKEY_PARAM, BuildConfig.OPEN_TMDB_MAP_API_KEY).build();

        URL url = new URL(builtUri.toString());

        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        InputStream inputStream = urlConnection.getInputStream();
        StringBuffer buffer = new StringBuffer();
        if (inputStream == null) {
            return null;
        }
        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            return null;
        }
        moviesJsonStr = buffer.toString();

        Log.d(LOG_TAG, "Buffer " + moviesJsonStr);

        getMoviesDataFromJson(moviesJsonStr);

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        return null;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                Log.e(LOG_TAG, "Error closing stream", e);
            }
        }
    }

    return null;
}

From source file:com.xing.android.sdk.network.request.RequestUtilsTest.java

@Test
public void appendParamsToBuilder() throws Exception {
    Uri uriBase = new Uri.Builder().scheme("test").authority("test").build();

    Uri.Builder builder = uriBase.buildUpon();

    // Check nothing happens
    RequestUtils.appendParamsToBuilder(builder, null);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check param with empty key will not be added
    List<Pair<String, String>> pairs = new ArrayList<>();
    pairs.add(new Pair<String, String>(null, null));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check param with empty value will not be added
    pairs.clear();//from  w  w w  . j a  v a 2  s.co  m
    pairs.add(new Pair<String, String>("test", null));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check actual param is added
    pairs.clear();
    pairs.add(new Pair<>("a", "a"));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase + "?a=a", builder.build().toString());

    // Check next 2 params will be appended
    pairs.clear();
    pairs.add(new Pair<>("b", "b"));
    pairs.add(new Pair<String, String>(null, "d"));
    pairs.add(new Pair<String, String>("f", null));
    pairs.add(new Pair<>("c", "c"));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase + "?a=a&b=b&c=c", builder.build().toString());
}

From source file:ph.com.globe.connect.AuthenticationActivity.java

/**
 * On activity create process./* w w w  .  j  a v a  2 s .co m*/
 *
 * @param savedInstanceState instance state
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    // call base create
    super.onCreate(savedInstanceState);

    // initialize web view
    final WebView webview = new WebView(this);

    // set content view of the activity
    setContentView(webview);

    // get the app id from intent
    final String appId = getIntent().getStringExtra("app_id");
    // get the app secret from intent
    final String appSecret = getIntent().getStringExtra("app_secret");

    // set web view client
    webview.setWebViewClient(new WebViewClient() {
        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param url current url
         * @return boolean
         */
        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // parse the uri
            final Uri uri = Uri.parse(url);

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }

        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param request web resource request
         * @return boolean
         */
        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            // parse the uri
            final Uri uri = Uri.parse(request.getUrl().toString());

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }
    });

    try {
        // set dialog url
        String DIALOG_URL = this.buildUrl(this.DIALOG_URL, appId);

        // load the url
        webview.loadUrl(DIALOG_URL);
    } catch (ApiException e) {
        e.printStackTrace();
    }
}

From source file:com.adamhurwitz.android.popularmovies.service.YouTubeService.java

@Override
protected void onHandleIntent(Intent intent) {
    String[] youTubeArray = intent.getStringArrayExtra("YOUTUBE_QUERY");

    // These two need to be declared outside the try/catch
    // so that they can be closed in the finally block.
    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;

    // Will contain the raw JSON response as a string.
    String jsonResponse = null;/* ww  w.  ja v  a2  s . c  om*/

    try {
        // Construct the URL to fetch data from and make the connection.
        Uri builtUri = Uri.parse(BASE_URL + youTubeArray[0] + VIDEOS).buildUpon()
                .appendQueryParameter(KEY_PARAMETER, KEY_CODE).build();
        URL url = new URL(builtUri.toString());
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        // See if the input stream is not null and a connection could be made. If it is null, do
        // not process any further.
        InputStream inputStream = urlConnection.getInputStream();
        StringBuilder buffer = new StringBuilder();
        if (inputStream == null) {
            return;
        }

        // Read the input stream to see if any valid response was give.
        reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while ((line = reader.readLine()) != null) {
            // Add new to make debugging easier.
            buffer.append(line).append("\n");
        }
        if (buffer.length() == 0) {
            // If the stream is empty, do not process any further.
            return;
        }

        jsonResponse = buffer.toString();

    } catch (IOException e) {
        // If there was no valid Google doodle data returned, there is no point in attempting to
        // parse it.
        Log.e(LOG_TAG, "Error, IOException.", e);
        return;
    } finally {
        // Make sure to close the connection and the reader no matter what.
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                Log.e(LOG_TAG, "Error closing stream ", e);
            }
        }
    }

    // return ArrayList of MovieData Objects
    parseJSONResponse(jsonResponse, youTubeArray[1]);

    // Any other case that gets here is an error that was not caught, so return null.
    return;
}