Example usage for android.net Uri encode

List of usage examples for android.net Uri encode

Introduction

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

Prototype

public static String encode(String s) 

Source Link

Document

Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme.

Usage

From source file:com.ocp.picasa.PicasaApi.java

public int getAlbumPhotos(AccountManager accountManager, SyncResult syncResult, AlbumEntry album,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    StringBuilder builder = new StringBuilder(BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append("/albumid/");
    builder.append(album.id);/*from   w  ww  . j  a  v  a 2 s.co m*/
    builder.append(BASE_QUERY_STRING);
    builder.append("&kind=photo");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = album.photosEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    // We need to reset the authtoken and retry only once.
                    if (!retry) {
                        retry = true;
                        accountManager.invalidateAuthToken(PicasaService.SERVICE_NAME, mAuth.authToken);
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                    break;
                default:
                    Log.e(Gallery.TAG, TAG + ": " + "getAlbumPhotos: " + builder.toString()
                            + ", unexpected status code " + operation.outStatus);
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the album/photos feed.
            album.photosEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mPhotoInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(Gallery.TAG, TAG + ": " + "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(Gallery.TAG, TAG + ": " + "getAlbumPhotos: " + e);
        ++syncResult.stats.numIoExceptions;
        e.printStackTrace();
    } catch (SAXException e) {
        Log.e(Gallery.TAG, TAG + ": " + "getAlbumPhotos: " + e);
        ++syncResult.stats.numParseExceptions;
        e.printStackTrace();
    }
    return RESULT_ERROR;
}

From source file:com.example.ishita.administrativeapp.AttendantActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from   www.j a v a  2  s  . co  m
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.profile) {
        /* Intent launch_profile= new Intent(getApplicationContext(),Profile.class);
         launch_profile.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         launch_profile.putExtra("EXIT",true);
         startActivity(launch_profile);*/
    } else if (id == R.id.about) {
        /*  AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle(String.format("%1$s", getString(R.string.app_name)));
          builder.setMessage(getResources().getText(R.string.about_text));
          builder.setPositiveButton("OK", null);
          builder.setIcon(R.mipmap.ic_launcher);
          AlertDialog welcomeAlert = builder.create();
          welcomeAlert.show();
          ((TextView) welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());*/
    } else if (id == R.id.contributors) {
        /* AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setTitle(String.format("%1$s", getString(R.string.contributors)));
         builder.setMessage(getResources().getText(R.string.contributors_text));
         builder.setPositiveButton("OK", null);
         //builder.setIcon(R.mipmap.nimbus_icon);
         AlertDialog welcomeAlert = builder.create();
         welcomeAlert.show();
         ((TextView) welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());*/
    } else if (id == R.id.bug) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        String uriText = "mailto:" + Uri.encode("ishitathakur@gmail.com") + "?subject="
                + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode(
                        "Hello, Ishita \nI want to report a bug/give feedback corresponding to the app EOutPass.\n.....\n\n-Your name");

        Uri uri = Uri.parse(uriText);
        intent.setData(uri);
        startActivity(Intent.createChooser(intent, "Send Email"));
    } else if (id == R.id.licenses) {
        /*  AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle(String.format("%1$s", getString(R.string.open_source_licenses)));
          builder.setMessage(getResources().getText(R.string.licenses_text));
          builder.setPositiveButton("OK", null);
          //builder.setIcon(R.mipmap.nimbus_icon);
          AlertDialog welcomeAlert = builder.create();
          welcomeAlert.show();
          ((TextView) welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());*/
    }
    return true;

}

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;//  w  ww .  j ava2 s.  c  om
        if (searchString == null) {
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(searchString));
        }
        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION,
                null, ContactsQuery.SORT_ORDER);
    }

    LogUtil.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")");
    return null;
}

From source file:aarddict.Volume.java

public String getArticleURL(String title) {
    String template = getArticleURLTemplate();
    if (template != null) {
        return template.replace("$1", Uri.encode(title));
    }/*from   w  ww . j a v a 2s. co  m*/
    return null;
}

From source file:com.android.dialer.calllog.ContactInfoHelper.java

/**
 * Determines the contact information for the given phone number.
 * <p>//w w w. ja v  a2s.c  om
 * It returns the contact info if found.
 * <p>
 * If no contact corresponds to the given phone number, returns {@link ContactInfo#EMPTY}.
 * <p>
 * If the lookup fails for some other reason, it returns null.
 */
private ContactInfo queryContactInfoForPhoneNumber(String number, String countryIso) {
    if (TextUtils.isEmpty(number)) {
        return null;
    }
    String contactNumber = number;
    if (!TextUtils.isEmpty(countryIso)) {
        // Normalize the number: this is needed because the PhoneLookup query below does not
        // accept a country code as an input.
        String numberE164 = PhoneNumberUtils.formatNumberToE164(number, countryIso);
        if (!TextUtils.isEmpty(numberE164)) {
            // Only use it if the number could be formatted to E164.
            contactNumber = numberE164;
        }
    }

    // The "contactNumber" is a regular phone number, so use the PhoneLookup table.
    Uri uri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(contactNumber));
    ContactInfo info = lookupContactFromUri(uri);
    if (info != null && info != ContactInfo.EMPTY) {
        info.formattedNumber = formatPhoneNumber(number, null, countryIso);
    } else if (mCachedNumberLookupService != null) {
        CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext,
                number);
        if (cacheInfo != null) {
            info = cacheInfo.getContactInfo().isBadData ? null : cacheInfo.getContactInfo();
        } else {
            info = null;
        }
    }
    return info;
}

From source file:com.timtory.wmgallery.picasa.PicasaApi.java

public int getAlbumPhotos(AccountManager accountManager, SyncResult syncResult, AlbumEntry album,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    String baseUrl = Settings.Secure.getString(mContentResolver, SETTINGS_PICASA_GDATA_BASE_URL_KEY);
    StringBuilder builder = new StringBuilder(baseUrl != null ? baseUrl : DEFAULT_BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append("/albumid/");
    builder.append(album.id);/*ww w .ja va2  s .  com*/
    builder.append(BASE_QUERY_STRING);
    builder.append("&kind=photo");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = album.photosEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    // We need to reset the authtoken and retry only once.
                    if (!retry) {
                        retry = true;
                        accountManager.invalidateAuthToken(PicasaService.SERVICE_NAME, mAuth.authToken);
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                    break;
                default:
                    Log.e(TAG, "getAlbumPhotos: " + builder.toString() + ", unexpected status code "
                            + operation.outStatus);
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the album/photos feed.
            album.photosEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mPhotoInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(TAG, "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numIoExceptions;
        e.printStackTrace();
    } catch (SAXException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numParseExceptions;
        e.printStackTrace();
    }
    return RESULT_ERROR;
}

From source file:fr.tvbarthel.apps.simpleweatherforcast.MainActivity.java

private boolean handleActionContactUs() {
    final String uriString = getString(R.string.contact_us_uri,
            Uri.encode(getString(R.string.contact_us_email)),
            Uri.encode(getString(R.string.contact_us_default_subject)));
    final Uri mailToUri = Uri.parse(uriString);
    Intent sendToIntent = new Intent(Intent.ACTION_SENDTO);
    sendToIntent.setData(mailToUri);//  w w  w  .  j  av  a  2s.co m
    startActivity(sendToIntent);
    return true;
}

From source file:com.albedinsky.android.support.intent.MapIntent.java

/**
 * Appends {@link #mLocationQuery} to the specified <var>uriBuilder</var>.
 * <p>// www .  j a v a2 s  . c om
 * <b>Note</b>, that before adding value of the location query there will be added also
 * {@code q=} query parameter. Also location query will be encoded via {@link Uri#encode(String)}.
 *
 * @param uriBuilder The builder where to append the location query value.
 */
private void appendLocationQuery(StringBuilder uriBuilder) {
    uriBuilder.append("q=").append(Uri.encode(mLocationQuery));
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static PublicScriptResult fetchScript(Context context, PublicScript script, String trollId,
        String trollPassword) throws QuotaExceededException, PublicScriptException, NetworkUnavailableException,
        HighUpdateRateException {/*  ww w  .java2 s  .com*/

    Log.i(TAG, String.format("Fetching in script=%s and troll=%s ", script, trollId));
    ScriptCategory category = script.category;
    int requestCount = computeRequestCount(context, script.category, trollId);
    //        if (requestCount >= category.quota) {
    if (requestCount >= (category.quota / 2)) {
        String format = "Quota is exceeded for category %s (script=%s) and troll=%s: %d%d";
        String message = String.format(format, category, script, trollId, requestCount, category.quota);
        Log.w(TAG, message);
        throw new QuotaExceededException(category, requestCount);
    }

    Date lastRequest = geLastRequest(context, script, trollId);
    if (System.currentTimeMillis() - lastRequest.getTime() < THIRTY_MINUTES) {
        throw new HighUpdateRateException(script, lastRequest);
    }

    String uuid = UUID.randomUUID().toString();
    createFetchLog(context, script, trollId, uuid);

    String url = String.format(script.url, Uri.encode(trollId), Uri.encode(trollPassword));
    PublicScriptResponse spResult = doHttpGET(url);
    Log.i(TAG, String.format("Script response: '%s'", spResult));

    if (spResult.hasError()) {
        saveFetch(context, script, trollId, uuid, MhDlaSQLHelper.STATUS_ERROR);
        throw new PublicScriptException(spResult);
    } else {

        saveFetch(context, script, trollId, uuid, MhDlaSQLHelper.STATUS_SUCCESS);

        String raw = spResult.getRaw();
        PublicScriptResult result = new PublicScriptResult(script, raw);

        return result;
    }

}

From source file:com.andrew.apolloMod.activities.QueryBrowserActivity.java

private Cursor getQueryCursor(AsyncQueryHandler async, String filter) {
    if (filter == null) {
        filter = "";
    }/*  w  w  w .ja  va 2s .c om*/
    String[] ccols = new String[] { BaseColumns._ID, Audio.Media.MIME_TYPE, Audio.Artists.ARTIST,
            Audio.Albums.ALBUM, Audio.Media.TITLE, "data1", "data2" };

    Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter));

    Cursor ret = null;
    if (async != null) {
        async.startQuery(0, null, search, ccols, null, null, null);
    } else {
        ret = MusicUtils.query(this, search, ccols, null, null, null);
    }
    return ret;
}