List of usage examples for android.net Uri toString
public abstract String toString();
From source file:edu.stanford.mobisocial.dungbeetle.SettingsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //TODO handle here. if (resultCode == RESULT_OK) { Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); if (uri == null) { editor.putString("ringtone", "none"); } else {/* ww w.j a v a 2 s . c o m*/ editor.putString("ringtone", uri.toString()); } editor.commit(); Log.w("settings", uri.toString()); } }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
private String getIconUriString(Source source, String drawableId) { // Fast path for empty icons if (TextUtils.isEmpty(drawableId) || "0".equals(drawableId)) { return null; }// w w w.j a v a 2 s. c o m // Fast path for icon URIs if (drawableId.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE) || drawableId.startsWith(ContentResolver.SCHEME_CONTENT) || drawableId.startsWith(ContentResolver.SCHEME_FILE)) { return drawableId; } Uri uri = source.getIconUri(drawableId); return uri == null ? null : uri.toString(); }
From source file:com.openerp.base.ir.Attachment.java
private OEDataRow uriToDataRow(Uri uri, Bitmap bitmap) { OEDataRow attachment = new OEDataRow(); String filename = ""; String file_type = ""; if (uri != null) { String[] file_info = getFileName(uri); filename = file_info[0];/*from w ww. j a va 2s . co m*/ file_type = file_info[1]; } attachment.put("name", filename); attachment.put("file_type", file_type); attachment.put("file_uri", (uri != null) ? uri.toString() : false); attachment.put("bitmap", (bitmap != null) ? bitmap : false); return attachment; }
From source file:de.unwesen.packrat.api.FeedReader.java
private void updateFeed(Uri uri, Handler handler) { // Log.d(LTAG, "Fetching feed: " + uri); // Convert Uri to URI... yes, it sucks. URI feed_uri = null;/*from w ww . j a v a2s.c o m*/ try { feed_uri = new URI(uri.toString()); } catch (URISyntaxException ex) { Log.e(LTAG, "Invalid feed URI: " + uri); Message m = handler.obtainMessage(FR_INVALID_FEED_URI); m.sendToTarget(); return; } // Construct request HttpGet request = new HttpGet(feed_uri); request.addHeader("Referer", REFERER_URL); HttpResponse response; try { response = sClient.execute(request); // Read response HttpEntity entity = response.getEntity(); if (null == entity) { Log.e(LTAG, "Feed is empty: " + uri); Message m = handler.obtainMessage(FR_EMPTY_FEED); m.sendToTarget(); return; } MediaParser parser = new MediaParser(); MediaParser.AtomFeed feed = parser.parse(entity.getContent()); if (null == feed) { Log.e(LTAG, "Unable to parse feed, exiting: " + uri); Message m = handler.obtainMessage(FR_FEED_PARSE_FAILURE); m.sendToTarget(); return; } LinkedList<Media> result = parseFeed(feed); if (null != result && result.size() > 0) { Message m = handler.obtainMessage(FR_SUCCESS, result); m.sendToTarget(); } else { Message m = handler.obtainMessage(FR_EMPTY_FEED); m.sendToTarget(); } } catch (IOException ex) { Log.w(LTAG, "IO exception: " + ex); Message m = handler.obtainMessage(FR_NETWORK_ERROR); m.sendToTarget(); } catch (Exception ex) { Log.e(LTAG, "An exception occurred when reading the feed: " + ex); Message m = handler.obtainMessage(FR_UNKNOWN_ERROR); m.sendToTarget(); } }
From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java
/** * {@inheritDoc}/*from www . j a v a 2 s . c om*/ */ @Override protected final void onNewIntent(final Intent intent) { final Uri uri = intent.getData(); Log.d(TAG, "new intent: " + intent.getAction()); Log.d(TAG, "intent: " + intent.getData()); if (uri != null) { Log.d(TAG, "importing: " + uri.toString()); this.importData(this, uri); } }
From source file:de.unwesen.web.DownloadCache.java
private String getCacheHash(Uri uri) { if (null == uri) { return null; }/*from w ww .j a va 2s. co m*/ // Create hash of URL MessageDigest m = null; try { m = MessageDigest.getInstance(HASH_ALGO); } catch (java.security.NoSuchAlgorithmException ex) { Log.e(LTAG, "No " + HASH_ALGO + " supported, caching is disabled!"); return null; } m.update(uri.toString().getBytes()); String digest = new BigInteger(1, m.digest()).toString(16); while (digest.length() < ((HASH_ALGO_SIZE / 8) * 2)) { digest = "0" + digest; } return digest; }
From source file:website.openeng.async.Connection.java
/** * Downloads any missing media files according to the mediaURL deckvar. * * @param data/*from ww w . j a va2 s . co m*/ * @return The return type contains data.resultType and an array of Integer in data.data. data.data[0] is the number * of total missing media, data.data[1] is the number of downloaded ones. */ private Payload doInBackgroundDownloadMissingMedia(Payload data) { Timber.i("DownloadMissingMedia"); HashMap<String, String> missingPaths = new HashMap<String, String>(); HashMap<String, String> missingSums = new HashMap<String, String>(); data.result = (Decks) data.data[0]; // pass it to the return object so we close the deck in the deck picker String syncName = "";// deck.getDeckName(); data.success = false; data.data = new Object[] { 0, 0, 0 }; // if (!deck.hasKey("mediaURL")) { // data.success = true; // return data; // } String urlbase = "";// deck.getVar("mediaURL"); if (urlbase.equals("")) { data.success = true; return data; } String mdir = "";// deck.mediaDir(true); int totalMissing = 0; int missing = 0; int grabbed = 0; Cursor cursor = null; try { cursor = null;// deck.getDB().getDatabase().rawQuery("SELECT filename, originalPath FROM media", null); String path = null; String f = null; while (cursor.moveToNext()) { f = cursor.getString(0); path = mdir + "/" + f; File file = new File(path); if (!file.exists()) { missingPaths.put(f, path); missingSums.put(f, cursor.getString(1)); Timber.d("Missing file: %s", f); } } } finally { if (cursor != null) { cursor.close(); } } totalMissing = missingPaths.size(); data.data[0] = totalMissing; if (totalMissing == 0) { data.success = true; return data; } publishProgress(Boolean.FALSE, totalMissing, 0, syncName); URL url = null; HttpURLConnection connection = null; String path = null; String sum = null; int readbytes = 0; byte[] buf = new byte[4096]; for (String file : missingPaths.keySet()) { try { android.net.Uri uri = android.net.Uri.parse(Uri.encode(urlbase, ":/@%") + Uri.encode(file)); url = new URI(uri.toString()).toURL(); connection = (HttpURLConnection) url.openConnection(); connection.connect(); if (connection.getResponseCode() == 200) { path = missingPaths.get(file); InputStream is = connection.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, 4096); FileOutputStream fos = new FileOutputStream(path); while ((readbytes = bis.read(buf, 0, 4096)) != -1) { fos.write(buf, 0, readbytes); Timber.d("Downloaded %d file: %s", readbytes, path); } fos.close(); // Verify with checksum sum = missingSums.get(file); if (true) {// sum.equals("") || sum.equals(Utils.fileChecksum(path))) { grabbed++; } else { // Download corrupted, delete file Timber.i("Downloaded media file %s failed checksum.", path); File f = new File(path); f.delete(); missing++; } } else { Timber.e("Connection error (" + connection.getResponseCode() + ") while retrieving media file " + urlbase + file); Timber.e("Connection message: " + connection.getResponseMessage()); if (missingSums.get(file).equals("")) { // Ignore and keep going missing++; } else { data.success = false; data.data = new Object[] { file }; return data; } } connection.disconnect(); } catch (URISyntaxException e) { Timber.e(e, "doInBackgroundDownloadMissingMedia URISyntaxException"); } catch (MalformedURLException e) { Timber.e(e, "MalformedURLException while download media file " + path); if (missingSums.get(file).equals("")) { // Ignore and keep going missing++; } else { data.success = false; data.data = new Object[] { file }; return data; } } catch (IOException e) { Timber.e(e, "IOException while download media file " + path); if (missingSums.get(file).equals("")) { // Ignore and keep going missing++; } else { data.success = false; data.data = new Object[] { file }; return data; } } finally { if (connection != null) { connection.disconnect(); } } publishProgress(Boolean.TRUE, totalMissing, grabbed + missing, syncName); } data.data[1] = grabbed; data.data[2] = missing; data.success = true; return data; }
From source file:com.hackensack.umc.activity.ProfileSelfieActivityCustomeCam.java
private void getImageUris(Uri imageUri, int selectedImageView) { switch (selectedImageView) { case 1:/*w ww .j a v a2s . c om*/ Log.v(TAG, "getImageUris_1:" + imageUri); pathDlFront = Base64Converter.createBase64StringFroImage(imageUri.toString(), ProfileSelfieActivityCustomeCam.this); uriDlFront = imageUri; Log.v(TAG, "getImageUri_2:" + imageUri); //allImagesSelectedListner.setUris(uriDlFront,pathDlFront); //CameraFunctionality.storeImagesInFolder(uriDlFront.toString(), ProfileSelfieActivity.this); // PhotoList.DlFront=pathDlFront; Log.v("uriDlFront", uriDlFront.toString()); break; case 2: pathDlBack = Base64Converter.createBase64StringFroImage(imageUri.toString(), ProfileSelfieActivityCustomeCam.this); uriDlback = imageUri; break; case 3: pathIcFront = Base64Converter.createBase64StringFroImage(imageUri.toString(), ProfileSelfieActivityCustomeCam.this); uriIcFront = imageUri; break; case 4: pathIcBack = Base64Converter.createBase64StringFroImage(imageUri.toString(), ProfileSelfieActivityCustomeCam.this); uriIcBack = imageUri; break; case 5: pathSelfie = Base64Converter.createBase64StringFroImage(imageUri.toString(), ProfileSelfieActivityCustomeCam.this); uriSelfie = imageUri; break; } }
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
private void photoSucess(Intent intent) { //URI????URI?URI?? //???try-catch??? Uri uri = intent.getData(); if (null == uri) { uri = mImageUri;//from w ww . j ava 2 s.co m } ContentResolver resolver = getContext().getContentResolver(); XPathResolver pathResolver = new XPathResolver(null == uri ? null : uri.toString(), "", getContext()); Bitmap bitmap = null; try { if (!mAllowEdit) { String path = pathResolver.resolve(); if (!XStringUtils.isEmptyString(path)) { bitmap = XUtils.decodeBitmap(path); } } else { //??????Android??? bitmap = intent.getExtras().getParcelable("data"); //?????URI if (bitmap == null) { bitmap = getCroppedBitmap(intent); } } } catch (OutOfMemoryError e) { mCallbackCtx.error("OutOfMemoryError when decode image."); return; } if (mDestType == DATA_URL) { int rotate = 0; String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = resolver.query(uri, cols, null, null, null); if (null != cursor) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (0 != rotate) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } bitmap = scaleBitmap(bitmap); processPicture(bitmap); bitmap.recycle(); bitmap = null; System.gc(); } else if (mTargetHeight > 0 && mTargetWidth > 0) { try { Bitmap scaleBitmap = scaleBitmap(bitmap); String fileName = XConfiguration.getInstance().getWorkDirectory() + RESIZED_PIC_NAME; OutputStream os = new FileOutputStream(fileName); scaleBitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os); os.close(); bitmap.recycle(); bitmap = null; scaleBitmap.recycle(); scaleBitmap = null; mCallbackCtx.success("file://" + fileName + "?" + System.currentTimeMillis()); System.gc(); } catch (Exception e) { mCallbackCtx.error("Error retrieving image."); return; } } else { mCallbackCtx.success(XConstant.FILE_SCHEME + pathResolver.resolve()); } }
From source file:com.frostwire.android.gui.transfers.TransferManager.java
public BittorrentDownload downloadTorrent(String uri, TorrentFetcherListener fetcherListener, String tempDownloadTitle) { String url = uri.trim();// w w w.j a v a 2s . c o m try { if (url.contains("urn%3Abtih%3A")) { //fixes issue #129: over-encoded url coming from intent url = url.replace("urn%3Abtih%3A", "urn:btih:"); } if (isAlreadyDownloadingTorrentByUri(url)) { return null; } Uri u = Uri.parse(url); String scheme = u.getScheme(); if (!scheme.equalsIgnoreCase("file") && !scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https") && !scheme.equalsIgnoreCase("magnet")) { LOG.warn("Invalid URI scheme: " + u.toString()); return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported); } BittorrentDownload download = null; if (fetcherListener == null) { if (scheme.equalsIgnoreCase("file")) { BTEngine.getInstance().download(new File(u.getPath()), null, null); } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) { download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle)); bittorrentDownloadsList.add(download); bittorrentDownloadsMap.put(download.getInfoHash(), download); } } else { if (scheme.equalsIgnoreCase("file")) { fetcherListener.onTorrentInfoFetched(FileUtils.readFileToByteArray(new File(u.getPath())), null, -1); } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) { // this executes the listener method when it fetches the bytes. download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle), fetcherListener); bittorrentDownloadsList.add(download); bittorrentDownloadsMap.put(download.getInfoHash(), download); incrementStartedTransfers(); return download; } return null; } incrementStartedTransfers(); return download; } catch (Throwable e) { LOG.warn("Error creating download from uri: " + url, e); return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported); } }