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.todoroo.astrid.notes.EditNoteActivity.java

public boolean activityResult(int requestCode, int resultCode, Intent data) {

    if (respondToPicture) {
        respondToPicture = false;//ww  w  .jav a  2  s. c om
        CameraResultCallback callback = new CameraResultCallback() {
            @Override
            public void handleCameraResult(Uri uri) {
                if (activity != null) {
                    activity.getIntent().putExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS, uri.toString());
                }
                pendingCommentPicture = uri;
                setPictureButtonToPendingPicture();
                commentField.requestFocus();
            }
        };

        return actFmCameraModule.activityResult(requestCode, resultCode, data, callback);
    } else {
        return false;
    }
}

From source file:com.polyvi.xface.extension.XAppExt.java

private void setIntentByUri(Intent intent, Uri uri) {
    if (!XConstant.FILE_SCHEME.contains(uri.getScheme())) {
        intent.setData(uri);//from  w ww.j  a  v a 2  s. co m
    } else {
        String mimeType = XFileUtils.getMIMEType(uri.toString());
        intent.setDataAndType(uri, XStringUtils.isEmptyString(mimeType) ? "*/*" : mimeType);
    }
}

From source file:com.example.mihai.inforoute.app.FetchWeatherTask.java

@Override
protected Void doInBackground(String... params) {

    // If there's no zip code, there's nothing to look up.  Verify size of params.
    if (params.length == 0) {
        return null;
    }/*from  w  w w .  j  ava 2  s .co  m*/
    String locationQuery = params[0];

    // 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 forecastJsonStr = null;

    String format = "json";
    String units = "metric";
    //int numDays = 14;

    try {
        // Construct the URL for the OpenWeatherMap query
        // Possible parameters are avaiable at OWM's forecast API page, at
        // http://openweathermap.org/API#forecast
        final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?";
        final String QUERY_PARAM = "q";
        final String FORMAT_PARAM = "mode";
        final String UNITS_PARAM = "units";
        final String DAYS_PARAM = "cnt";

        Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, params[0])
                .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units)
                .appendQueryParameter(DAYS_PARAM, params[1]).build();

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

        // Create the request to OpenWeatherMap, and open the connection
        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) {
            // Nothing to do.
            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;
        }
        forecastJsonStr = buffer.toString();
        getWeatherDataFromJson(forecastJsonStr, locationQuery);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    } 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.example.android.popularmovies.app.FetchMoviesTask.java

@Override
protected ArrayList<HashMap<String, String>> doInBackground(String... params) {
    // verify page number
    if (params.length == 0) {
        return null;
    }/*from ww  w  . j a  v a  2s . co  m*/

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;
    String moviesJsonStr = null;
    String PARAM_PAGE = "page";
    String PAGE_TYPE = BuildConfig.THE_MOVIE_DB_API_POPULAR_URL;

    // get page type from shared preferences
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    String pageType = sharedPreferences.getString(mContext.getString(R.string.pref_page_type),
            mContext.getString(R.string.pref_page_type_popular_movies));
    Log.i(LOG_TAG, pageType);
    if (pageType.equalsIgnoreCase(mContext.getString(R.string.pref_page_type_highest_rated))) {
        PAGE_TYPE = BuildConfig.THE_MOVIE_DB_API_TOP_RETED_URL;
    }

    try {
        // Construct the URL for the themovieDB query
        // Possible parameters are avaiable at themovieDB API page, at
        // https://www.themoviedb.org/documentation/api
        Uri builtUri = Uri.parse(BuildConfig.THE_MOVIE_DB_API_BASE_URL + PAGE_TYPE).buildUpon()
                .appendQueryParameter(BuildConfig.THE_MOVIE_DB_API_APIKEY_PARAM,
                        BuildConfig.THE_MOVIE_DB_API_KEY)
                .appendQueryParameter(PARAM_PAGE, params[0]).build();

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

        Log.i(LOG_TAG, builtUri.toString());

        // Create the request to themovieDB, and open the connection
        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) {
            // Nothing to do.
            return null;
        }
        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
            // But it does make debugging a *lot* easier if you print out the completed
            // buffer for debugging.
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            // Stream was empty.  No point in parsing.
            return null;
        }
        moviesJsonStr = buffer.toString();

    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        // If the code didn't successfully get the weather data, there's no point in attemping
        // to parse it.
        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);
            }
        }
    }

    try {
        return appendMoviesDataFromJsonToAdapter(moviesJsonStr);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }

    return null;
}

From source file:alberthsu.sunshine.app.FetchWeatherTask.java

@Override
protected Void doInBackground(String... params) {

    // If there's no zip code, there's nothing to look up.  Verify size of params.
    if (params.length == 0) {
        return null;
    }/*  w ww  . j a va2s .  c  om*/
    String locationQuery = params[0];

    // 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 forecastJsonStr = null;

    String format = "json";
    String units = "metric";
    int numDays = 14;

    try {
        // Construct the URL for the OpenWeatherMap query
        // Possible parameters are avaiable at OWM's forecast API page, at
        // http://openweathermap.org/API#forecast
        final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?";
        final String QUERY_PARAM = "q";
        final String FORMAT_PARAM = "mode";
        final String UNITS_PARAM = "units";
        final String DAYS_PARAM = "cnt";

        Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, params[0])
                .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units)
                .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)).build();

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

        // Create the request to OpenWeatherMap, and open the connection
        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) {
            // Nothing to do.
            return null;
        }
        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
            // But it does make debugging a *lot* easier if you print out the completed
            // buffer for debugging.
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            // Stream was empty.  No point in parsing.
            return null;
        }
        forecastJsonStr = buffer.toString();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        // If the code didn't successfully get the weather data, there's no point in attemping
        // to parse it.
        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);
            }
        }
    }

    try {
        getWeatherDataFromJson(forecastJsonStr, numDays, locationQuery);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
    // This will only happen if there was an error getting or parsing the forecast.
    return null;
}

From source file:com.ofalvai.bpinfo.api.bkkinfo.BkkInfoClient.java

@Override
public void fetchAlert(@NonNull String id, final @NonNull AlertDetailListener listener,
        @NonNull AlertRequestParams params) {
    Uri url = buildAlertDetailUrl(params, id);

    LOGI(TAG, "API request: " + url.toString());

    JsonObjectRequest request = new JsonObjectRequest(url.toString(), null,
            new Response.Listener<JSONObject>() {
                @Override//from   w  w w  .  java2s .  co  m
                public void onResponse(JSONObject response) {
                    onAlertDetailResponse(listener, response);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    listener.onError(error);
                }
            });
    request.setRetryPolicy(getRetryPolicy());

    mRequestQueue.add(request);
    createAndStartTrace("network_alert_detail_bkk");
}

From source file:com.ofalvai.bpinfo.api.bkkinfo.BkkInfoClient.java

@Override
public void fetchAlertList(final @NonNull AlertRequestParams params) {
    // If a request is in progress, we don't proceed. The response callback will notify every subscriber
    if (mRequestInProgress)
        return;/* ww w.  jav a2s . co  m*/

    final Uri url = buildAlertListUrl(params);

    LOGI(TAG, "API request: " + url.toString());

    JsonObjectRequest request = new JsonObjectRequest(url.toString(), null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    onAlertListResponse(response);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    EventBus.getDefault().post(new AlertListErrorMessage(error));
                }
            });
    request.setRetryPolicy(getRetryPolicy());

    mRequestInProgress = true;
    mRequestQueue.add(request);
}

From source file:com.swisscom.android.sunshine.data.FetchWeatherTask.java

@Override
protected Void doInBackground(String... params) {

    // If there's no zip code, there's nothing to look up.  Verify size of params.
    if (params.length == 0) {
        return null;
    }//from  www.  j av  a2 s  .  c om
    String locationQuery = params[0];

    // 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 forecastJsonStr = null;

    String format = "json";
    String units = "metric";
    int numDays = 14;

    try {
        // Construct the URL for the OpenWeatherMap query
        // Possible parameters are avaiable at OWM's forecast API page, at
        // http://openweathermap.org/API#forecast
        final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?";
        final String QUERY_PARAM = "q";
        final String FORMAT_PARAM = "mode";
        final String UNITS_PARAM = "units";
        final String DAYS_PARAM = "cnt";

        Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, params[0])
                .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units)
                .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)).build();

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

        // Create the request to OpenWeatherMap, and open the connection
        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) {
            // Nothing to do.
            return null;
        }
        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
            // But it does make debugging a *lot* easier if you print out the completed
            // buffer for debugging.
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            // Stream was empty.  No point in parsing.
            return null;
        }
        forecastJsonStr = buffer.toString();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        // If the code didn't successfully get the weather data, there's no point in attemping
        // to parse it.
        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);
            }
        }
    }

    try {
        return getWeatherDataFromJson(forecastJsonStr, numDays, locationQuery);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
    // This will only happen if there was an error getting or parsing the forecast.
    return null;
}

From source file:com.commontime.cordova.audio.AudioHandler.java

/**
 * Executes the request and returns PluginResult.
 * @param action       The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackContext      The callback context used when calling back into JavaScript.
 * @return             A PluginResult object with a status and message.
 *///from w  ww .j av a2s  . c om
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    CordovaResourceApi resourceApi = webView.getResourceApi();
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    if (action.equals("startRecordingAudio")) {
        String target = args.getString(1);
        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }
        this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr));
    }

    else if (action.equals("startRecordingAudioWithCompression")) {
        String target = args.getString(1);
        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }

        // set defaults
        Integer sampleRate = 44100;
        Integer channels = 1;

        JSONObject options = args.getJSONObject(2);

        try {
            channels = options.getInt("NumberOfChannels");
            sampleRate = options.getInt("SampleRate");
        } catch (JSONException e) {
            channels = 1;
            sampleRate = 44100;
        }
        // for use within resumeRecord, these values must be consistent when resume record is called.
        this.audioChannels = channels;
        this.audioSampleRate = sampleRate;

        this.startRecordingAudioWithCompression(args.getString(0), FileHelper.stripFileProtocol(fileUriStr),
                channels, sampleRate);
    } else if (action.equals("pauseRecordingAudio")) {
        this.pauseRecordingAudio(args.getString(0));
    } else if (action.equals("resumeRecordingAudio")) {
        String target = args.getString(1);
        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }

        this.resumeRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr),
                this.audioChannels, this.audioSampleRate);
    } else if (action.equals("stopRecordingAudio")) {
        this.stopRecordingAudio(args.getString(0));
    } else if (action.equals("startPlayingAudio")) {
        String target = args.getString(1);
        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }
        this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr));
    } else if (action.equals("seekToAudio")) {
        this.seekToAudio(args.getString(0), args.getInt(1));
    } else if (action.equals("pausePlayingAudio")) {
        this.pausePlayingAudio(args.getString(0));
    } else if (action.equals("stopPlayingAudio")) {
        this.stopPlayingAudio(args.getString(0));
    } else if (action.equals("setVolume")) {
        try {
            this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
        } catch (NumberFormatException nfe) {
            //no-op
        }
    } else if (action.equals("getCurrentPositionAudio")) {
        float f = this.getCurrentPositionAudio(args.getString(0));
        callbackContext.sendPluginResult(new PluginResult(status, f));
        return true;
    } else if (action.equals("getDurationAudio")) {
        float f = this.getDurationAudio(args.getString(0), args.getString(1));
        callbackContext.sendPluginResult(new PluginResult(status, f));
        return true;
    }

    //REM mods
    else if (action.equals("getRecordDbLevel")) {
        float f = this.getAudioRecordDbLevel(args.getString(0));
        callbackContext.sendPluginResult(new PluginResult(status, f));
        return true;
    }
    //---

    else if (action.equals("create")) {
        String id = args.getString(0);
        String src = FileHelper.stripFileProtocol(args.getString(1));
        getOrCreatePlayer(id, src);
    } else if (action.equals("release")) {
        boolean b = this.release(args.getString(0));
        callbackContext.sendPluginResult(new PluginResult(status, b));
        return true;
    } else if (action.equals("messageChannel")) {
        messageChannel = callbackContext;
        return true;
    } else { // Unrecognized action.
        return false;
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));

    return true;
}

From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java

@Override
public int update(final Uri uri, final ContentValues values, final String selection,
        final String[] selectionArgs) {
    if (uri.getPathSegments().size() != 1)
        throw new IllegalArgumentException(uri.toString());

    final String address = uri.getLastPathSegment();

    final int count = helper.getWritableDatabase().update(DATABASE_TABLE, values, KEY_ADDRESS + "=?",
            new String[] { address });

    if (count > 0)
        getContext().getContentResolver().notifyChange(uri, null);

    return count;
}