List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.securecomcode.text.contacts.ContactAccessor.java
public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) { LinkedList<String> numberList = new LinkedList<String>(); Cursor cursor = null;/*ww w . ja v a2s.c om*/ try { cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint)), null, null, null, null); while (cursor != null && cursor.moveToNext()) { numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER))); } } finally { if (cursor != null) cursor.close(); } return numberList; }
From source file:com.appteam.nimbus.activity.homeActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override//from ww w .j a v a2 s .c o m public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.navigation_to_profile) { // Handle the camera action Intent i = new Intent(homeActivity.this, Profile.class); startActivity(i); } else if (id == R.id.aboutus_nav) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.app_name))); builder.setMessage(getResources().getText(R.string.aboutus_text)); builder.setPositiveButton("OK", null); builder.setIcon(R.mipmap.nimbus16); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); ((TextView) welcomeAlert.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } else if (id == R.id.feedback_nav) { Intent intent = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("appteam.nith@gmail.com") + "?subject=" + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode( "Hello, Appteam \nI want to report a bug/give feedback corresponding to the app Nimbus 2k16.\n.....\n\n-Your name"); Uri uri = Uri.parse(uriText); intent.setData(uri); startActivity(Intent.createChooser(intent, "Send Email")); } else if (id == R.id.opensourcelicenses_nav) { 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()); } else if (id == R.id.contributors_nav) { 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.notifications) { startActivity(new Intent(homeActivity.this, ViewActivity.class)); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.github.kanata3249.ffxieq.android.FoodSelectorActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { Food food = getDAO().instantiateFood(mLongClickingItemId); String name = food.getName(); Intent intent;//from www .j av a 2 s . c o m if (food != null) { String[] urls = getResources().getStringArray(R.array.SearchURIs); String url; url = null; switch (item.getItemId()) { case R.id.WebSearch0: url = urls[0]; break; case R.id.WebSearch1: url = urls[1]; break; case R.id.WebSearch2: url = urls[2]; break; case R.id.WebSearch3: url = urls[3]; break; case R.id.WebSearch4: url = urls[4]; break; case R.id.WebSearch5: url = urls[5]; break; case R.id.WebSearch6: url = urls[6]; break; case R.id.WebSearch7: url = urls[7]; break; default: url = null; break; } if (url != null) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + Uri.encode(name.split("\\+")[0]))); startActivity(intent); return true; } } return super.onContextItemSelected(item); }
From source file:com.librelio.activity.StartupActivity.java
private String getAdvertisingLinkURL() { return new StringBuilder(getString(R.string.get_advertising_link_url)).toString() .replace(PARAM_CLIENT, Uri.encode(LibrelioApplication.getClientName(self()))) .replace(PARAM_APP, Uri.encode(LibrelioApplication.getMagazineName(self()))); }
From source file:at.flack.receiver.SmsReceiver.java
public static String getContactName(Context context, String phoneNumber) { ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor == null) { return null; }// www. j a v a2 s. c o m String contactName = null; if (cursor.moveToFirst()) { contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return contactName; }
From source file:vn.mbm.phimp.me.gallery3d.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 www . j av a 2 s.c o 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(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:de.ub0r.android.websms.WebSMSReceiver.java
/** * Displays notification if sending failed * * @param context context/*from ww w. ja va 2s. co m*/ * @param specs {@link de.ub0r.android.websms.connector.common.ConnectorSpec} * @param command {@link de.ub0r.android.websms.connector.common.ConnectorCommand} */ private static void displaySendingFailedNotification(final Context context, final ConnectorSpec specs, final ConnectorCommand command) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); String to = Utils.joinRecipients(command.getRecipients(), ", "); final Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(INTENT_SCHEME_SMSTO + ":" + Uri.encode(to)), context, WebSMS.class); // add pending intent i.putExtra(Intent.EXTRA_TEXT, command.getText()); i.putExtra(WebSMS.EXTRA_ERRORMESSAGE, specs.getErrorMessage()); i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent cIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_notify_sms_failed) .setContentTitle(context.getString(R.string.notify_failed) + " " + specs.getErrorMessage()) .setContentText(to + ": " + command.getText()).setTicker(context.getString(R.string.notify_failed_)) .setWhen(System.currentTimeMillis()).setContentIntent(cIntent).setAutoCancel(true) .setLights(NOTIFICATION_LED_COLOR, NOTIFICATION_LED_ON, NOTIFICATION_LED_OFF); final String s = p.getString(WebSMS.PREFS_FAIL_SOUND, null); if (!TextUtils.isEmpty(s)) { b.setSound(Uri.parse(s)); } if (p.getBoolean(WebSMS.PREFS_FAIL_VIBRATE, false)) { b.setVibrate(VIBRATE_ON_FAIL_PATTERN); } NotificationManager mNotificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationMgr.notify(getNotificationID(), b.build()); // show a toast as well final String em = specs.getErrorMessage(); if (em != null) { Toast.makeText(context, em, Toast.LENGTH_LONG).show(); } }
From source file:com.hichinaschool.flashcards.libanki.Media.java
/** * Percent-escape UTF-8 characters in local image filenames. * // w w w . ja v a 2 s. co m * @param string The string to search for image references and escape the filenames. * @return The string with the filenames of any local images percent-escaped as UTF-8. */ public String escapeImages(String string) { Matcher m = fMediaRegexps[1].matcher(string); StringBuffer sb = new StringBuffer(); while (m.find()) { if (fRemoteFilePattern.matcher(m.group(2)).find()) { m.appendReplacement(sb, m.group()); } else { String tagBegin = m.group(1).substring(0, m.start(2)); String fname = m.group(2); String tagEnd = m.group(1).substring(m.end(2)); String tag = tagBegin + Uri.encode(fname) + tagEnd; m.appendReplacement(sb, tag); } } m.appendTail(sb); return sb.toString(); }
From source file:hackathon.openrice.CardsActivity.java
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); Bundle extras = getIntent().getExtras(); String keyword = null;/*from w w w. j a va2s. c o m*/ if (extras != null) { ArrayList<String> text = extras.getStringArrayList(RecognizerIntent.EXTRA_RESULTS); if (text != null) { for (String t : text) { String temp = t.toLowerCase().trim(); if (temp.startsWith("search")) { keyword = temp.substring(6).trim(); } } } } Card info = new Card(this); info.setText("Loading data..."); cards.add(info); RetrieveImage task = new RetrieveImage(); // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy if (location != null) { // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project) lastKnownLocation = location; if (lastKnownLocation != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { lastKnownLocation = location; } else { lastKnownLocation = location; } } } } }; locationProvider = new LocationProvider(this, locationListener); double x, y; if (lastKnownLocation != null) { x = lastKnownLocation.getLatitude(); y = lastKnownLocation.getLongitude(); } else { x = 22.3049989; y = 114.17925600000001; } if (keyword != null) { //Log.d("FFFF", keyword); task.execute( "http://openricescraper.herokuapp.com/?x=" + x + "&y=" + y + "&keyword=" + Uri.encode(keyword)); } else { task.execute("http://openricescraper.herokuapp.com/?x=" + x + "&y=" + y); } mCardScroller = new CardScrollView(this); mCardScroller.setAdapter(new CardAdapter(cards)); mCardScroller.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { final String className = "com.wikitude.samples.SampleCamActivity"; try { final Intent intent = new Intent(ctx, Class.forName(className)); intent.putExtra(EXTRAS_KEY_ACTIVITY_TITLE_STRING, "5.2 Adding Radar"); intent.putExtra(EXTRAS_KEY_ACTIVITY_ARCHITECT_WORLD_URL, "samples/5_Browsing$Pois_2_Adding$Radar/index.html"); if (poiData != null) { JSONArray pass = new JSONArray(); final String ATTR_ID = "id"; final String ATTR_NAME = "name"; final String ATTR_DESCRIPTION = "description"; final String ATTR_LATITUDE = "latitude"; final String ATTR_LONGITUDE = "longitude"; final String ATTR_ALTITUDE = "altitude"; int i = position - 1; //for (int i = 0; i < poiData.length(); i++) { JSONObject jsonObj = (JSONObject) poiData.get(i); final HashMap<String, String> poiInformation = new HashMap<String, String>(); poiInformation.put(ATTR_ID, String.valueOf(i)); poiInformation.put(ATTR_NAME, new String(jsonObj.getString("name").getBytes("ISO-8859-1"), "UTF-8")); if (jsonObj.getString("score").equalsIgnoreCase("null")) { poiInformation.put(ATTR_DESCRIPTION, new String(jsonObj.getString("address").getBytes("ISO-8859-1"), "UTF-8")); } else { poiInformation.put(ATTR_DESCRIPTION, "" + jsonObj.getDouble("score") + ", " + new String(jsonObj.getString("address").getBytes("ISO-8859-1"), "UTF-8")); } poiInformation.put(ATTR_LATITUDE, String.valueOf(jsonObj.get("x"))); poiInformation.put(ATTR_LONGITUDE, String.valueOf(jsonObj.get("y"))); final float UNKNOWN_ALTITUDE = -32768f; // equals "AR.CONST.UNKNOWN_ALTITUDE" in JavaScript (compare AR.GeoLocation specification) // Use "AR.CONST.UNKNOWN_ALTITUDE" to tell ARchitect that altitude of places should be on user level. Be aware to handle altitude properly in locationManager in case you use valid POI altitude value (e.g. pass altitude only if GPS accuracy is <7m). poiInformation.put(ATTR_ALTITUDE, String.valueOf(UNKNOWN_ALTITUDE)); pass.put(new JSONObject(poiInformation)); //} intent.putExtra("poiData", pass.toString()); } /* launch activity */ ctx.startActivity(intent); } catch (Exception e) { /* * may never occur, as long as all SampleActivities exist and are * listed in manifest */ Toast.makeText(ctx, className + "\nnot defined/accessible", Toast.LENGTH_SHORT).show(); } } }); setContentView(mCardScroller); IntentFilter filter = new IntentFilter(); filter.addAction("com.ours.asyncisover"); filter.addCategory("android.intent.category.DEFAULT"); registerReceiver(myBroadcastReceiver, filter); isReceiverRegistered = true; }
From source file:org.wso2.emm.agent.services.operationMgt.OperationManager.java
/** * Retrieve device application information. * * @param operation - Operation object.//from w w w.jav a 2 s . c om */ public void getApplicationList(org.wso2.emm.agent.beans.Operation operation) throws AndroidAgentException { ArrayList<DeviceAppInfo> apps = new ArrayList<>(appList.getInstalledApps().values()); JSONArray result = new JSONArray(); RuntimeInfo runtimeInfo = new RuntimeInfo(context); Map<String, Application> applications = runtimeInfo.getAppMemory(); for (DeviceAppInfo infoApp : apps) { JSONObject app = new JSONObject(); try { Application application = applications.get(infoApp.getPackagename()); app.put(APP_INFO_TAG_NAME, Uri.encode(infoApp.getAppname())); app.put(APP_INFO_TAG_PACKAGE, infoApp.getPackagename()); app.put(APP_INFO_TAG_VERSION, infoApp.getVersionCode()); if (application != null) { app.put(Constants.Device.USS, application.getUss()); } result.put(app); } catch (JSONException e) { operation.setStatus(resources.getString(R.string.operation_value_error)); resultBuilder.build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } } operation.setOperationResponse(result.toString()); operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Application list sent"); } }