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.tapjoy.TapjoyConnectCore.java

/**
 * Initialize data from the device information and application info.
 * This data is used in our URL connection to the Tapjoy server. 
 *///from  w w w  .j  a  v  a 2s . com
private void init() {
    PackageManager manager = context.getPackageManager();

    try {
        // ANDROID_ID
        androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

        // Get app version.
        PackageInfo packageInfo = manager.getPackageInfo(context.getPackageName(), 0);
        appVersion = packageInfo.versionName;

        // Device platform.  Same as device type.
        deviceType = TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE;
        platformName = TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE;

        // Get the device model.
        deviceModel = android.os.Build.MODEL;
        deviceManufacturer = android.os.Build.MANUFACTURER;

        // Get the Android OS Version.
        deviceOSVersion = android.os.Build.VERSION.RELEASE;

        // Get the device country and language code.
        deviceCountryCode = Locale.getDefault().getCountry();
        deviceLanguage = Locale.getDefault().getLanguage();

        // Tapjoy SDK Library version.
        libraryVersion = TapjoyConstants.TJC_LIBRARY_VERSION_NUMBER;

        SharedPreferences settings = context.getSharedPreferences(TapjoyConstants.TJC_PREFERENCE, 0);

        try {
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

            if (telephonyManager != null) {
                deviceID = telephonyManager.getDeviceId();

                carrierName = telephonyManager.getNetworkOperatorName();
                carrierCountryCode = telephonyManager.getNetworkCountryIso();

                // getNetworkOperator() returns MCC + MNC, so make sure it's 5 or 6 digits total.
                // MCC is 3 digits
                // MNC is 2 or 3 digits
                if (telephonyManager.getNetworkOperator() != null
                        && (telephonyManager.getNetworkOperator().length() == 5
                                || telephonyManager.getNetworkOperator().length() == 6)) {
                    mobileCountryCode = telephonyManager.getNetworkOperator().substring(0, 3);
                    mobileNetworkCode = telephonyManager.getNetworkOperator().substring(3);
                }
            }

            TapjoyLog.i(TAPJOY_CONNECT, "deviceID: " + deviceID);

            boolean invalidDeviceID = false;

            //----------------------------------------
            // Is the device ID null or empty?
            //----------------------------------------
            if (deviceID == null) {
                TapjoyLog.e(TAPJOY_CONNECT, "Device id is null.");
                invalidDeviceID = true;
            } else
            //----------------------------------------
            // Is this an emulator device ID?
            //----------------------------------------
            if (deviceID.length() == 0 || deviceID.equals("000000000000000") || deviceID.equals("0")) {
                TapjoyLog.e(TAPJOY_CONNECT, "Device id is empty or an emulator.");
                invalidDeviceID = true;
            }
            //----------------------------------------
            // Valid device ID.
            //----------------------------------------
            else {
                // Lower case the device ID.
                deviceID = deviceID.toLowerCase();
            }

            TapjoyLog.i(TAPJOY_CONNECT, "ANDROID SDK VERSION: " + android.os.Build.VERSION.SDK);

            // Is this at least Android 2.3+?
            // Then let's get the serial.
            if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 9) {
                TapjoyLog.i(TAPJOY_CONNECT, "TRYING TO GET SERIAL OF 2.3+ DEVICE...");

                // THIS CLASS IS ONLY LOADED FOR ANDROID 2.3+
                TapjoyHardwareUtil hardware = new TapjoyHardwareUtil();

                serialID = hardware.getSerial();

                // Is there no IMEI or MEID?
                if (invalidDeviceID) {
                    deviceID = serialID;
                }

                TapjoyLog.i(TAPJOY_CONNECT, "====================");
                TapjoyLog.i(TAPJOY_CONNECT, "SERIAL: deviceID: [" + deviceID + "]");
                TapjoyLog.i(TAPJOY_CONNECT, "====================");

                //----------------------------------------
                // Is the device ID null or empty?
                //----------------------------------------
                if (deviceID == null) {
                    TapjoyLog.e(TAPJOY_CONNECT, "SERIAL: Device id is null.");
                    invalidDeviceID = true;
                } else
                //----------------------------------------
                // Is this an emulator device ID?
                //----------------------------------------
                if (deviceID.length() == 0 || deviceID.equals("000000000000000") || deviceID.equals("0")
                        || deviceID.equals("unknown")) {
                    TapjoyLog.e(TAPJOY_CONNECT, "SERIAL: Device id is empty or an emulator.");
                    invalidDeviceID = true;
                }
                //----------------------------------------
                // Valid device ID.
                //----------------------------------------
                else {
                    // Lower case the device ID.
                    deviceID = deviceID.toLowerCase();
                    invalidDeviceID = false;
                }
            }

            // Is the device ID invalid?  This is probably an emulator or pre-production device.
            if (invalidDeviceID) {
                StringBuffer buff = new StringBuffer();
                buff.append("EMULATOR");
                String deviceId = settings.getString(TapjoyConstants.PREF_EMULATOR_DEVICE_ID, null);

                // Do we already have an emulator device id stored for this device?
                if (deviceId != null && !deviceId.equals("")) {
                    deviceID = deviceId;
                }
                // Otherwise generate a deviceID for emulator testing.
                else {
                    String constantChars = "1234567890abcdefghijklmnopqrstuvw";

                    for (int i = 0; i < 32; i++) {
                        int randomChar = (int) (Math.random() * 100);
                        int ch = randomChar % 30;
                        buff.append(constantChars.charAt(ch));
                    }

                    deviceID = buff.toString().toLowerCase();

                    // Save the emulator device ID in the prefs so we can reuse it.
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(TapjoyConstants.PREF_EMULATOR_DEVICE_ID, deviceID);
                    editor.commit();
                }
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting deviceID. e: " + e.toString());
            deviceID = null;
        }

        // Set the userID to the deviceID as the initial value.
        if (userID.length() == 0)
            userID = deviceID;

        // Save the SHA-2 hash of the device id.
        sha2DeviceID = TapjoyUtil.SHA256(deviceID);

        // Get screen density, dimensions and layout.
        try {
            // This is a backwards compatibility fix for Android 1.5 which has no display metric API.
            // If this is 1.6 or higher, then load the class, otherwise the class never loads and
            // no crash occurs.
            if (Integer.parseInt(android.os.Build.VERSION.SDK) > 3) {
                TapjoyDisplayMetricsUtil displayMetricsUtil = new TapjoyDisplayMetricsUtil(context);

                deviceScreenDensity = "" + displayMetricsUtil.getScreenDensity();
                deviceScreenLayoutSize = "" + displayMetricsUtil.getScreenLayoutSize();
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting screen density/dimensions/layout: " + e.toString());
        }

        // Get mac address.
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

            if (wifiManager != null) {
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();

                if (wifiInfo != null) {
                    macAddress = wifiInfo.getMacAddress();

                    if (macAddress != null && macAddress.length() > 0) {
                        macAddress = macAddress.toUpperCase();
                        sha1MacAddress = TapjoyUtil.SHA1(macAddress);
                    }
                }
            }
        } catch (Exception e) {
            TapjoyLog.e(TAPJOY_CONNECT, "Error getting device mac address: " + e.toString());
        }

        // Alternate market.
        if (getFlagValue(TapjoyConnectFlag.ALTERNATE_MARKET) != null) {
            marketName = getFlagValue(TapjoyConnectFlag.ALTERNATE_MARKET);

            // Check for existing/supported market names.
            ArrayList<String> supportedMarketNames = new ArrayList<String>();
            supportedMarketNames.add(TapjoyConnectFlag.MARKET_GFAN);

            // Warning for undefined market names.
            if (!supportedMarketNames.contains(marketName)) {
                Log.w(TAPJOY_CONNECT, "Warning -- undefined ALTERNATE_MARKET: " + marketName);
            }
        }

        // Get the referral URL
        String tempReferralURL = settings.getString(TapjoyConstants.PREF_REFERRAL_URL, null);
        if (tempReferralURL != null && !tempReferralURL.equals(""))
            referralURL = tempReferralURL;

        // Get the client package name.
        clientPackage = context.getPackageName();

        TapjoyLog.i(TAPJOY_CONNECT, "Metadata successfully loaded");

        TapjoyLog.i(TAPJOY_CONNECT, "APP_ID = [" + appID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "ANDROID_ID: [" + androidID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "CLIENT_PACKAGE = [" + clientPackage + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "deviceID: [" + deviceID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "sha2DeviceID: [" + sha2DeviceID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_DEVICE_SERIAL_ID + ": [" + serialID + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_DEVICE_MAC_ADDRESS + ": [" + macAddress + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_DEVICE_SHA1_MAC_ADDRESS + ": [" + sha1MacAddress + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "deviceName: [" + deviceModel + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceManufacturer: [" + deviceManufacturer + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceType: [" + deviceType + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "libraryVersion: [" + libraryVersion + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "deviceOSVersion: [" + deviceOSVersion + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "COUNTRY_CODE: [" + deviceCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "LANGUAGE_CODE: [" + deviceLanguage + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "density: [" + deviceScreenDensity + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "screen_layout: [" + deviceScreenLayoutSize + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "carrier_name: [" + carrierName + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "carrier_country_code: [" + carrierCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_MOBILE_COUNTRY_CODE + ": [" + mobileCountryCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT,
                "" + TapjoyConstants.TJC_MOBILE_NETWORK_CODE + ": [" + mobileNetworkCode + "]");
        TapjoyLog.i(TAPJOY_CONNECT, "" + TapjoyConstants.TJC_MARKET_NAME + ": [" + marketName + "]");

        TapjoyLog.i(TAPJOY_CONNECT, "referralURL: [" + referralURL + "]");

        if (connectFlags != null) {
            TapjoyLog.i(TAPJOY_CONNECT, "Connect Flags:");
            TapjoyLog.i(TAPJOY_CONNECT, "--------------------");

            Set<Entry<String, String>> entries = connectFlags.entrySet();
            Iterator<Entry<String, String>> iterator = entries.iterator();

            while (iterator.hasNext()) {
                Entry<String, String> item = iterator.next();
                TapjoyLog.i(TAPJOY_CONNECT,
                        "key: " + item.getKey() + ", value: " + Uri.encode(item.getValue()));
            }
        }
    } catch (Exception e) {
        TapjoyLog.e(TAPJOY_CONNECT, "Error initializing Tapjoy parameters.  e=" + e.toString());
    }
}

From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        // There are two types of searches, one which displays all contacts and
        // one which filters contacts by a search query. If mSearchTerm is set
        // then a search query has been entered and the latter should be used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that searches the entire
            // Contacts table
            setContentUri(ContactsQuery.CONTENT_URI);
        } else {//from   ww w  . j a  va 2 s  . co  m
            // Since there's a search string, use the special content Uri that searches the
            // Contacts table. The URI consists of a base Uri and the search string.
            setContentUri(Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm)));
        }

        //           if(ParserApplication.isContactsAccessPolicyAllowed()){

        // Returns a new CursorLoader for querying the Contacts table. No arguments are used
        // for the selection clause. The search string is either encoded onto the content URI,
        // or no contacts search string is used. The other search criteria are constants. See
        // the ContactsQuery interface.
        return new CursorLoader(getActivity(), getContentUri(), ContactsQuery.PROJECTION,
                ContactsQuery.SELECTION, null, ContactsQuery.SORT_ORDER);
        //           }
        //           else {
        //               /**
        //                * If you return null here then the access to the content is actually blocked!
        //                */
        //               return null;
        //           }
    }

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

From source file:cx.ring.service.LocalService.java

@NonNull
public static CallContact findContactByNumber(@NonNull ContentResolver res, String number) {
    //Log.w(TAG, "findContactByNumber " + number);
    CallContact c = null;/*from   ww  w  . ja v  a2 s. c  o  m*/
    try {
        Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
        Cursor result = res.query(uri, PHONELOOKUP_PROJECTION, null, null, null);
        if (result == null) {
            Log.w(TAG, "findContactByNumber " + number + " can't find contact.");
            return findContactBySipNumber(res, number);
        }
        if (result.moveToFirst()) {
            int iID = result.getColumnIndex(ContactsContract.Contacts._ID);
            int iKey = result.getColumnIndex(ContactsContract.Data.LOOKUP_KEY);
            int iName = result.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
            int iPhoto = result.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
            c = new CallContact(result.getLong(iID), result.getString(iKey), result.getString(iName),
                    result.getLong(iPhoto));
            lookupDetails(res, c);
            Log.w(TAG, "findContactByNumber " + number + " found " + c.getDisplayName());
        }
        result.close();
    } catch (Exception e) {
        Log.w(TAG, e);
    }
    if (c == null) {
        Log.w(TAG, "findContactByNumber " + number + " can't find contact.");
        c = findContactBySipNumber(res, number);
    }
    return c;
}

From source file:io.asv.mtgocr.ocrreader.OcrCaptureActivity.java

public void doSearch(String searchText) {
    //save and show
    CardInfo cardinfo = new CardInfo(searchText, "", "", "", "");
    persistInfo(cardinfo);/*w w w . ja  v  a 2  s.  c  om*/

    //region create objectGetterCardinfo
    mLstHandlers.add(myHandler);
    int myIdx = mLstHandlers.size() - 1;
    mIdxCardInfoInLstCInfo.add(myIdx);
    mLstCardInfo.add(cardinfo);
    //MtgDataprovider
    IDataProvider myDataProvider = new MtgDataProvider(this, mLstHandlers.get(myIdx), myIdx);
    mLstDataProviders.add(myDataProvider);
    mIdxInPersistor.add(getIdxCardInfoInPersistor());

    // mLstHandlers.set(myIdx, myHandler); String query =  );
    mLstDataProviders.get(myIdx).GetCardInfo(Uri.encode(searchText), mLstCardInfo.get(myIdx));
}

From source file:com.example.findmygf.MapActivity.java

private ArrayList<String> QueryYahooPlaceForMeAPIs() {
    String uriPlace = Uri.encode(my_country + " " + my_city);

    yahooPlaceAPIsQuery = yahooPlaceApisBase + "%22" + uriPlace + "%22" + yahooapisFormat;

    String woeidString = QueryYahooWeather(yahooPlaceAPIsQuery);
    Document woeidDoc = convertStringToDocument(woeidString);
    return parseWOEID(woeidDoc);
}

From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;//w ww.j  a v  a  2s .co m

        // There are two types of searches, one which displays all contacts
        // and
        // one which filters contacts by a search query. If mSearchTerm is
        // set
        // then a search query has been entered and the latter should be
        // used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that
            // searches the entire
            // Contacts table
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            // Since there's a search string, use the special content Uri
            // that searches the
            // Contacts table. The URI consists of a base Uri and the search
            // string.
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm));
        }

        // Returns a new CursorLoader for querying the Contacts table. No
        // arguments are used
        // for the selection clause. The search string is either encoded
        // onto the content URI,
        // or no contacts search string is used. The other search criteria
        // are constants. See
        // the ContactsQuery interface.
        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION,
                null, ContactsQuery.SORT_ORDER);
    }

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

From source file:com.example.findmygf.MapActivity.java

private ArrayList<String> QueryYahooPlaceForPartnerAPIs() {
    String uriPlace = Uri.encode(p_country + " " + p_city);

    yahooPlaceAPIsQuery = yahooPlaceApisBase + "%22" + uriPlace + "%22" + yahooapisFormat;

    String woeidString = QueryYahooWeather(yahooPlaceAPIsQuery);
    Document woeidDoc = convertStringToDocument(woeidString);
    return parseWOEID(woeidDoc);
}

From source file:com.android.gallery3d.filtershow.FilterShowActivity.java

public void completeSaveImage(Uri saveUri) {
    if (mSharingImage && mSharedOutputFile != null) {
        // Image saved, we unblock the content provider
        Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
                Uri.encode(mSharedOutputFile.getAbsolutePath()));
        ContentValues values = new ContentValues();
        values.put(SharedImageProvider.PREPARE, false);
        getContentResolver().insert(uri, values);
    }/* ww  w.j  a  v  a2s  . co  m*/
    setResult(RESULT_OK, new Intent().setData(saveUri));
    hideSavingProgress();
    finish();
}

From source file:com.raibow.yamahaspk.filtershow.FilterShowActivity.java

public void completeSaveImage(Uri saveUri) {
    if (saveUri == null) {
        hideSavingProgress();//from   w ww  . j  a v a 2 s.c o  m

        CharSequence text = getString(R.string.save_image_failed);
        Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
        toast.show();

        finish();
    } else {
        if (mSharingImage && mSharedOutputFile != null) {
            // Image saved, we unblock the content provider
            Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
                    Uri.encode(mSharedOutputFile.getAbsolutePath()));
            ContentValues values = new ContentValues();
            values.put(SharedImageProvider.PREPARE, false);
            getContentResolver().insert(uri, values);
        }
        setResult(RESULT_OK, new Intent().setData(saveUri));
        hideSavingProgress();
        finish();
    }

}

From source file:com.markupartist.sthlmtraveling.RoutesActivity.java

/**
 * Constructs a search routes data URI.//from   w w  w  .  j ava 2 s . co m
 * @param startPoint the start point
 * @param endPoint the end point
 * @param time the time, pass null for now
 * @param isTimeDeparture true if the time is departure time, false if arrival
 * @return the data uri
 */
public static Uri createRoutesUri(Site startPoint, Site endPoint, Time time, boolean isTimeDeparture) {
    Uri routesUri;

    String timeString = "";
    String startLat = "";
    String startLng = "";
    String endLat = "";
    String endLng = "";

    if (time != null) {
        timeString = time.format2445();
    }
    if (startPoint.getLocation() != null) {
        startLat = String.valueOf(startPoint.getLocation().getLatitude());
        startLng = String.valueOf(startPoint.getLocation().getLongitude());
    }
    if (endPoint.getLocation() != null) {
        endLat = String.valueOf(endPoint.getLocation().getLatitude());
        endLng = String.valueOf(endPoint.getLocation().getLongitude());
    }

    routesUri = Uri.parse(String.format(
            "journeyplanner://routes?" + "start_point=%s" + "&start_point_id=%s" + "&start_point_lat=%s"
                    + "&start_point_lng=%s" + "&end_point=%s" + "&end_point_id=%s" + "&end_point_lat=%s"
                    + "&end_point_lng=%s" + "&time=%s" + "&isTimeDeparture=%s",
            Uri.encode(startPoint.getName()), startPoint.getId(), startLat, startLng,
            Uri.encode(endPoint.getName()), endPoint.getId(), endLat, endLng, timeString, isTimeDeparture));

    return routesUri;
}