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:au.com.wallaceit.reddinator.RedditData.java

public JSONArray getSubredditSearch(String query) throws RedditApiException {
    JSONArray subreddits = new JSONArray();
    String url = STANDARD_ENDPOINT + "/subreddits/search.json?q=" + Uri.encode(query);
    try {//w w  w  . java 2 s . co  m
        subreddits = getJSONFromUrl(url, false).getJSONObject("data").getJSONArray("children");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return subreddits;
}

From source file:com.personalcapital.personalperks.PerkNotificationService.java

private void createNotification(Intent intent) {
    int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, 1);
    String perkId = intent.getStringExtra(Perk.PERK_ID);
    Perk perk = SessionManager.getInstance().getPerkWithPerkId(perkId);

    /*//w w w.j  a v  a 2s .  co m
    ArrayList<Notification> notificationPages = new ArrayList<Notification>();
            
    int stepCount = mRecipe.recipeSteps.size();
            
    for (int i = 0; i < stepCount; ++i) {
    Recipe.RecipeStep recipeStep = mRecipe.recipeSteps.get(i);
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    style.bigText(recipeStep.stepText);
    style.setBigContentTitle(String.format(
            getResources().getString(R.string.step_count), i + 1, stepCount));
    style.setSummaryText("");
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setStyle(style);
    notificationPages.add(builder.build());
    }
            
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
            
    if (mRecipe.recipeImage != null) {
    Bitmap recipeImage = Bitmap.createScaledBitmap(
            AssetUtils.loadBitmapAsset(this, mRecipe.recipeImage),
            Constants.NOTIFICATION_IMAGE_WIDTH, Constants.NOTIFICATION_IMAGE_HEIGHT, false);
    builder.setLargeIcon(recipeImage);
    }
    builder.setContentTitle(mRecipe.titleText);
    builder.setContentText(mRecipe.summaryText);
    builder.setSmallIcon(R.mipmap.ic_notification_recipe);
            
    Notification notification = builder
        .extend(new NotificationCompat.WearableExtender()
                .addPages(notificationPages))
        .build();
    mNotificationManager.notify(Constants.NOTIFICATION_ID, notification);
    */

    ArrayList<Notification> notificationPages = new ArrayList<Notification>();

    if (perk.barCodeImage != null) {
        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
        style.bigPicture(perk.barCodeImage);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setStyle(style);
        builder.setContentText(perk.modoCheckoutCode);
        notificationPages.add(builder.build());
    }

    //        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    //        style.bigText(recipeStep.stepText);
    //        style.setBigContentTitle(String.format(getResources().getString(R.string.step_count), i + 1, stepCount));
    //            style.setSummaryText("");
    //            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    //            builder.setStyle(style);
    //            notificationPages.add(builder.build());

    // Build an intent for an action to view a map
    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode(perk.address));
    mapIntent.setData(geoUri);
    PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, 0);

    NotificationCompat.Action mapAction = new NotificationCompat.Action.Builder(R.drawable.ic_map,
            getString(R.string.map), mapPendingIntent).build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    if (perk.logoImage != null) {
        Bitmap recipeImage = Bitmap.createScaledBitmap(perk.logoImage, 280, 280, false);
        builder.setLargeIcon(recipeImage);
    }
    builder.setContentTitle(perk.merchantName);
    builder.setContentText(perk.description);
    builder.setSmallIcon(R.drawable.ic_launcher);

    Notification notification = builder
            .extend(new NotificationCompat.WearableExtender().addPages(notificationPages).addAction(mapAction))
            .build();
    NotificationManagerCompat.from(this).notify(notificationId, notification);
}

From source file:com.example.android.xyztouristattractions.ui.DetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Some small additions to handle "up" navigation correctly
        Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        // Check if up activity needs to be created (usually when
        // detail screen is opened from a notification or from the
        // Wearable app
        if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getActivity().isTaskRoot()) {

            // Synthesize parent stack
            TaskStackBuilder.create(getActivity()).addNextIntentWithParentStack(upIntent).startActivities();
        }//w  w w .  j a  v a  2s  .  c o m

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // On Lollipop+ we finish so to run the nice animation
            getActivity().finishAfterTransition();
            return true;
        }

        // Otherwise let the system handle navigating "up"
        return false;
    case R.id.map:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(
                Uri.parse(Constants.MAPS_INTENT_URI + Uri.encode(mAttraction.name + ", " + mAttraction.city)));
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.yammp.app.TrackFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    if (mCursor == null)
        return false;

    Intent intent;//from  ww w.  jav a  2 s .  c  o m

    switch (item.getItemId()) {
    case PLAY_SELECTION:
        int position = mSelectedPosition;

        if (mPlaylistId == PLAYLIST_QUEUE) {
            MusicUtils.setQueuePosition(position);
            return true;
        }
        MusicUtils.playAll(getActivity(), mCursor, position);
        return true;
    case DELETE_ITEMS:
        intent = new Intent(INTENT_DELETE_ITEMS);
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY_PATH,
                Uri.withAppendedPath(Audio.Media.EXTERNAL_CONTENT_URI, Uri.encode(String.valueOf(mSelectedId)))
                        .toString());
        intent.putExtras(bundle);
        startActivity(intent);
        return true;
    case SEARCH:
        doSearch();
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:org.tigase.mobile.utils.AvatarHelper.java

protected static Bitmap loadAvatar(BareJID jid, int size) {
    Bitmap bmp = null;//from  www.  ja  v  a  2  s.co  m

    Log.v(TAG, "loading avatar with size " + size);

    Cursor cursor = context.getContentResolver().query(
            Uri.parse(RosterProvider.VCARD_URI + "/" + Uri.encode(jid.toString())), null, null, null, null);
    try {
        if (cursor.moveToNext()) {
            // we found avatar in our store
            byte[] avatar = cursor.getBlob(cursor.getColumnIndex(VCardsCacheTableMetaData.FIELD_DATA));
            if (avatar != null) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                Bitmap bmp1 = BitmapFactory.decodeByteArray(avatar, 0, avatar.length, options);
                if (bmp1 != null) {
                    bmp1.recycle();
                }
                // options.inSampleSize = calculateSize(options, 96, 96);
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                options.inSampleSize = calculateSize(options, size, size);
                options.inJustDecodeBounds = false;
                bmp = BitmapFactory.decodeByteArray(avatar, 0, avatar.length, options);
            }
        } else {
            // no avatar in our store - checking for avatar in Android
            // contacts
            Uri photoUri = SyncAdapter.getAvatarUriFromContacts(context.getContentResolver(), jid);
            if (photoUri != null) {
                InputStream input = ContactsContract.Contacts
                        .openContactPhotoInputStream(context.getContentResolver(), photoUri);
                if (input != null) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inJustDecodeBounds = true;
                    Bitmap bmp1 = BitmapFactory.decodeStream(input, null, options);
                    if (bmp1 != null) {
                        bmp1.recycle();
                    }
                    // options.inSampleSize = calculateSize(options, 96,
                    // 96);
                    input.close();
                    input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(),
                            photoUri);
                    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                    options.inSampleSize = calculateSize(options, size, size);
                    options.inJustDecodeBounds = false;
                    bmp = BitmapFactory.decodeStream(input, null, options);
                    input.close();
                }
            }
        }
    } catch (Exception ex) {
        Log.v(TAG, "exception retrieving avatar for " + jid.toString(), ex);
    } finally {
        cursor.close();
    }
    return bmp;
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an email Intent for the given message details and opens the application choooser for this Intent
 *
 * @param recipient the recipient's email address
 * @param subject the subject of the message
 * @param body the body text as a string
 * @param captionRes the string resource ID for the application chooser's window title
 * @param restrictToPackage an optional package name that the Intent may be restricted to (or null)
 * @param context the Context instance to start the Intent from
 * @throws Exception if there was an error trying to launch the email Intent
 *//*w ww  .  jav a 2 s.c  om*/
public static void sendMail(final String recipient, final String subject, final String body,
        final int captionRes, final String restrictToPackage, final Context context) throws Exception {
    final String uriString = "mailto:" + Uri.encode(recipient) + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(body);
    final Uri uri = Uri.parse(uriString);
    final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(uri);
    if (restrictToPackage != null && restrictToPackage.length() > 0) {
        emailIntent.setPackage(restrictToPackage);
        if (context != null) {
            // launch the target app directly
            context.startActivity(emailIntent);
        }
    } else {
        if (context != null) {
            // offer a selection of all applications that can handle the email Intent
            context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes)));
        }
    }
}

From source file:com.visva.voicerecorder.utils.Utils.java

public static Uri getContactUriTypeFromPhoneNumber(ContentResolver resolver, String phoneNo, int index) {
    Uri result = null;/*  www .  jav a  2  s .  c  om*/
    if (phoneNo == "" || "null".equals(phoneNo)) {
        phoneNo = "111111111";
    }
    String[] projection = { ContactsContract.Contacts._ID, ContactsContract.PhoneLookup.DISPLAY_NAME,
            ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.PHOTO_URI,
            ContactsContract.PhoneLookup.LOOKUP_KEY };
    Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNo));
    Cursor cursor = resolver.query(lookupUri, projection, null, null, null);
    if (cursor == null)
        return null;
    if (cursor.moveToFirst()) {
        if (cursor.getString(index) != null)
            result = Uri.parse(cursor.getString(index));
    }
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
    return result;
}

From source file:net.giovannicapuano.galax.controller.User.java

/**
 * Send a message to an user.//from  w  w  w .  j a v  a 2  s  . com
 */
public static Status sendMessage(User to, String text, Context context) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("text", text));

    try {
        String body = Utils.postData("/user/message/" + Uri.encode(to.getUsername()), params, context)
                .getBody();
        android.util.Log.v("Chat", body);

        JSONObject json = new JSONObject(body);

        int statusCode = json.getInt("status");
        String error = statusCode == Status.SUCCESS ? null : json.getString("error");
        return new Status(statusCode, error);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.yammp.fragment.TrackFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    if (mCursor == null)
        return false;

    Intent intent;/*w  w  w.jav  a  2  s  . co  m*/

    switch (item.getItemId()) {
    case PLAY_SELECTION:
        int position = mSelectedPosition;

        if (mPlaylistId == PLAYLIST_QUEUE) {
            mUtils.setQueuePosition(position);
            return true;
        }
        mUtils.playAll(mCursor, position);
        return true;
    case DELETE_ITEMS:
        intent = new Intent(INTENT_DELETE_ITEMS);
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY_PATH,
                Uri.withAppendedPath(Audio.Media.EXTERNAL_CONTENT_URI, Uri.encode(String.valueOf(mSelectedId)))
                        .toString());
        intent.putExtras(bundle);
        startActivity(intent);
        return true;
    case SEARCH:
        doSearch();
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java

private void initializeButtons() {
    initializeServiceButtons();//from  ww w  .  j a va  2 s .co m
    initializeDemoButton();
    initializeEnableNotificationButton();

    mImproveTransliterationTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String uriText = "mailto:android@abhijitvalluri.com" + "?subject="
                    + Uri.encode("Improve Transliterations for <SPECIFY_LANGUAGE>") + "&body="
                    + Uri.encode("<MESSAGE>");

            Uri uri = Uri.parse(uriText);

            Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
            sendIntent.setData(uri);
            startActivity(Intent.createChooser(sendIntent, "Send email"));
        }
    });

    mRateAppTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("market://details?id=" + Constants.PACKAGE_NAME);
            Intent gotoPlayStore = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            gotoPlayStore.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(gotoPlayStore);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + Constants.PACKAGE_NAME)));
            }
        }
    });
}