List of usage examples for android.net Uri toString
public abstract String toString();
From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java
public SubTrip addIntermediateStops(Context context, SubTrip subTrip, JourneyQuery query) throws IOException { Uri u = Uri.parse(apiEndpoint2()); Uri.Builder b = u.buildUpon();// w w w .ja v a 2 s. c o m b.appendEncodedPath("journey/v1/intermediate/"); b.appendQueryParameter("ident", query.ident); b.appendQueryParameter("seqnr", query.seqnr); b.appendQueryParameter("reference", subTrip.reference); u = b.build(); HttpHelper httpHelper = HttpHelper.getInstance(context); HttpURLConnection connection = httpHelper.getConnection(u.toString()); String rawContent; int statusCode = connection.getResponseCode(); switch (statusCode) { case 200: rawContent = httpHelper.getBody(connection); try { JSONObject baseResponse = new JSONObject(rawContent); if (baseResponse.has("stops")) { JSONArray intermediateStopJsonArray = baseResponse.getJSONArray("stops"); for (int i = 0; i < intermediateStopJsonArray.length(); i++) { subTrip.intermediateStop .add(IntermediateStop.fromJson(intermediateStopJsonArray.getJSONObject(i))); } } else { Log.w(TAG, "Invalid response when fetching intermediate stops."); } } catch (JSONException e) { Log.w(TAG, "Could not parse the reponse for intermediate stops."); } break; case 400: rawContent = httpHelper.getErrorBody(connection); try { BadResponse br = BadResponse.fromJson(new JSONObject(rawContent)); Log.e(TAG, "Invalid response for intermediate stops: " + br.toString()); } catch (JSONException e) { Log.e(TAG, "Could not parse the reponse for intermediate stops."); } default: Log.e(TAG, "Status code not OK from intermediate stops API, was " + statusCode); } return subTrip; }
From source file:org.planetmono.dcuploader.ActivityUploader.java
private int queryOrientation(Uri uri) { Log.d(Application.TAG, "querying " + uri.toString()); ContentResolver cr = ActivityUploader.this.getContentResolver(); int orientation = 0; Cursor c = cr.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION, }, null, null, null); if (c != null) { c.moveToFirst();/*from w ww. ja v a 2 s . c o m*/ orientation = c.getInt(0); c.close(); return orientation; } /* If there's no such item in ContentResolver, query EXIF */ return queryExifOrientation(uri.getPath()); }
From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.TracksStore.java
public void addToFavorites(String idTrack) { //"me/favorites/" + TRACK_ID final Uri uri = Uri.parse("http://api.soundcloud.com/me/favorites/" + idTrack + ".json"); final HttpPut put = new HttpPut(uri.toString()); final Track track = createTrack(); final boolean[] result = new boolean[1]; try {/*from w ww . j a v a 2 s . c om*/ executeRequest(put, new ResponseHandler() { public void handleResponse(InputStream in) throws IOException { parseFavoritesResponse(in, new ResponseAddToFavorites() { @Override public void parseResponse(JSONObject response) throws JSONException { result[0] = parseTrack(response, track); } }); // parseSingleResponse(in, new ResponseParserSingle() { // @Override // public void parseResponse(JSONObject jsonTrack) throws JSONException { // result[0] = parseTrack(jsonTrack, track); // } // }); } }); //return result[0] ? track : null; } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not add to favorites the track with id: " + idTrack); } }
From source file:com.remobile.file.LocalFilesystem.java
@Override public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName, Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException { // Check to see if the destination directory exists String newParent = this.filesystemPathForURL(destURL); File destinationDir = new File(newParent); if (!destinationDir.exists()) { // The destination does not exist so we should fail. throw new FileNotFoundException("The source does not exist"); }/* w ww. ja va 2s. co m*/ // Figure out where we should be copying to final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory); Uri dstNativeUri = toNativeUri(destinationURL); Uri srcNativeUri = srcFs.toNativeUri(srcURL); // Check to see if source and destination are the same file if (dstNativeUri.equals(srcNativeUri)) { throw new InvalidModificationException("Can't copy onto itself"); } if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) { throw new InvalidModificationException("Source URL is read-only (cannot move)"); } File destFile = new File(dstNativeUri.getPath()); if (destFile.exists()) { if (!srcURL.isDirectory && destFile.isDirectory()) { throw new InvalidModificationException("Can't copy/move a file to an existing directory"); } else if (srcURL.isDirectory && destFile.isFile()) { throw new InvalidModificationException("Can't copy/move a directory to an existing file"); } } if (srcURL.isDirectory) { // E.g. Copy /sdcard/myDir to /sdcard/myDir/backup if (dstNativeUri.toString().startsWith(srcNativeUri.toString() + '/')) { throw new InvalidModificationException("Can't copy directory into itself"); } copyDirectory(srcFs, srcURL, destFile, move); } else { copyFile(srcFs, srcURL, destFile, move); } return makeEntryForURL(destinationURL); }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java
/** * Opens the binary input stream from a HEX file. A Uri to the stream is given * /*w w w. j a v a 2 s . c o m*/ * @param stream * the Uri to the stream * @return the binary input stream with Intel HEX data * @throws FileNotFoundException */ private HexInputStream openInputStream(final Uri stream) throws FileNotFoundException, IOException { if (stream.getScheme().equals("http")) { return new HexInputStream(new HttpGet(stream.toString())); } return new HexInputStream(getContentResolver().openInputStream(stream)); }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
public void imageSharing(Intent data, String type) { // Get the Uri of the selected file Uri uri = data.getData(); Log.d("imageSharing - type", type + " @"); Log.d("File Uri: ", uri.toString() + " #"); // Get the path String path = null;/*from w w w . jav a 2 s . c o m*/ try { path = getPath(this, uri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("File Path: ", path + " #"); if (path != null) { String userNum = prefs.getString(stored_user_country_code, "") + prefs.getString(stored_user_mobile_no, ""); String fileName = System.currentTimeMillis() + getFileFormat(path); String msg; if (type.equals("video")) { msg = "VID-" + userNum + "-" + fileName; } else if (type.equals("audio")) { msg = "AUD-" + userNum + "-" + fileName; } else { msg = "IMG-" + userNum + "-" + fileName; } String numb = prefs.getString(stored_chatuserNumber, ""); Log.d("nnumb", numb + " #"); String savefileuri = saveImage(path, fileName, stripNumber(numb)); if (savefileuri.equals(FILE_SIZE_ERROR + "")) { Toast toast = Toast.makeText(getApplicationContext(), "you upload file size is exceed to 30 MB", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (!savefileuri.equals("")) { Log.d("msg1", msg + " !"); sendInitmsg(msg, numb); new AsyncTaskUploadFile(savefileuri, msg).execute(); } else { Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_SHORT).show(); } } }
From source file:com.cordova.photo.CameraLauncher.java
/** * Applies all needed transformation to the image received from the gallery. */*from w ww .j a v a2s .co m*/ * @param destType In which form should we return the image * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ private void processResultFromGallery(int destType, Intent intent) { Uri uri = intent.getData(); if (uri == null) { if (croppedUri != null) { uri = croppedUri; } else { this.failPicture("null data from photo library"); return; } } int rotate = 0; // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.activity); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); this.orientationCorrected = true; } catch (OutOfMemoryError oom) { this.orientationCorrected = false; } } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { // Did we modify the image? if ((this.targetHeight > 0 && this.targetWidth > 0) || (this.correctOrientation && this.orientationCorrected)) { try { String modifiedPath = this.ouputModifiedBitmap(bitmap, uri); // The modified image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.callbackContext .success("file://" + modifiedPath + "?" + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.callbackContext.success(uri.toString()); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } }
From source file:com.abc.driver.TruckActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CellSiteConstants.TAKE_PICTURE || requestCode == CellSiteConstants.PICK_PICTURE) { Uri uri = null; if (requestCode == CellSiteConstants.TAKE_PICTURE) { uri = imageUri;//from w ww. j ava 2 s . c o m } else if (requestCode == CellSiteConstants.PICK_PICTURE) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().getMyTruck().setLicenseImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } // doCrop(); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false); mTLPiv.setImageBitmap(scaledBmp); isPortraitChanged = true; Log.d(TAG, "onActivityResult PICK_PICTURE"); mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_LICENSE_URL); } else if (requestCode == CellSiteConstants.CROP_PICTURE) { Log.d(TAG, "crop picture"); // processFile(); if (data != null) { Bundle extras = data.getExtras(); Bitmap photo = extras.getParcelable("data"); trcukLicenseBmp = photo; mTLPiv.setImageBitmap(trcukLicenseBmp); mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(trcukLicenseBmp), CellSiteConstants.UPDATE_DRIVER_LICENSE_URL); isPortraitChanged = true; } } else if (requestCode == CellSiteConstants.TAKE_PICTURE2 || requestCode == CellSiteConstants.PICK_PICTURE2) { Uri uri = null; if (requestCode == CellSiteConstants.TAKE_PICTURE2) { uri = imageUri; } else if (requestCode == CellSiteConstants.PICK_PICTURE2) { uri = data.getData(); } String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG, "filePath =" + filePath); Log.d(TAG, "uri=" + uri.toString()); imageUri = Uri.fromFile(new File(filePath)); } else // { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show(); return; } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); File srcFile = new File(uri.getPath()); if (srcFile.exists()) { try { Utils.copyFile(srcFile, tmpFile); app.getUser().getMyTruck().setPhotoImageUrl(tmpFile.getAbsolutePath()); } catch (Exception e) { Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show(); return; } } else { Log.d(TAG, "Logic error, should not come to here"); Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); return; } imageUri = Uri.fromFile(tmpFile); } // doCrop(); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false); mTPiv.setImageBitmap(scaledBmp); // s isChanged = true; mUpdateImageTask = new UpdateImageTask(); mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(), Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_PHOTO_URL); } else if (requestCode == CellSiteConstants.UPDATE_TRUCK_MOBILE_REQUSET) { Log.d(TAG, "mobile changed"); if (app.getUser().getMyTruck().getMobileNum() == null) { mTMtv.setText(app.getUser().getMobileNum()); app.getUser().getMyTruck().setMobileNum(app.getUser().getMobileNum()); } else { mTMtv.setText(app.getUser().getMyTruck().getMobileNum()); } } }
From source file:com.BeatYourRecord.SubmitActivity.java
private String getFilePathFromUri(Uri uri) throws IOException { Cursor cursor = managedQuery(uri, null, null, null, null); if (cursor.getCount() == 0) { throw new IOException(String.format("cannot find data from %s", uri.toString())); } else {/*from w w w. j a va 2 s .c om*/ cursor.moveToFirst(); } String filePath = cursor.getString(cursor.getColumnIndex(Video.VideoColumns.DATA)); permfilepath = filePath; cursor.close(); return filePath; }
From source file:com.BeatYourRecord.SubmitActivity.java
private File getFileFromUri(Uri uri) throws IOException { Cursor cursor = managedQuery(uri, null, null, null, null); if (cursor.getCount() == 0) { throw new IOException(String.format("cannot find data from %s", uri.toString())); } else {//from ww w .j av a 2s . c om cursor.moveToFirst(); } String filePath = cursor.getString(cursor.getColumnIndex(Video.VideoColumns.DATA)); //log.v("filePath",filePath); permfilepath = filePath; File file = new File(filePath); cursor.close(); return file; }