Example usage for android.net Uri toString

List of usage examples for android.net Uri toString

Introduction

In this page you can find the example usage for android.net Uri toString.

Prototype

public abstract String toString();

Source Link

Document

Returns the encoded string representation of this URI.

Usage

From source file:Main.java

public static String buildAccountName(Uri serverBaseUrl, String username) {
    if (serverBaseUrl.getScheme() == null) {
        serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
    }/*from   w  ww .j a  v  a 2  s  .  c o  m*/

    // Remove http:// or https://
    String url = serverBaseUrl.toString();
    if (url.contains("://")) {
        url = url.substring(serverBaseUrl.toString().indexOf("://") + 3);
    }
    String accountName = username + "@" + url;

    return accountName;
}

From source file:Main.java

public static Bitmap decodeUri(Uri selectedImage, ContentResolver contentResolver, ImageView imageView)
        throws FileNotFoundException {

    int originalImageId = Integer.parseInt(selectedImage.toString()
            .substring(selectedImage.toString().lastIndexOf("/") + 1, selectedImage.toString().length()));

    return MediaStore.Images.Thumbnails.getThumbnail(contentResolver, originalImageId,
            MediaStore.Images.Thumbnails.MINI_KIND, null);
}

From source file:no.norrs.projects.andronary.utils.HttpUtil.java

public static HttpResponse PUT(final Uri uri, List<NameValuePair> data) throws IOException {
    return PUT(uri.toString(), data);
}

From source file:no.norrs.projects.andronary.utils.HttpUtil.java

public static HttpResponse POST(final Uri uri, List<NameValuePair> data) throws IOException {
    return POST(uri.toString(), data);
}

From source file:Main.java

static InputStream openRemoteInputStream(Uri uri) {
    URL finalUrl;//from   w ww .  ja  va  2 s. c  o m
    try {
        finalUrl = new URL(uri.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
    HttpURLConnection connection;
    try {
        connection = (HttpURLConnection) finalUrl.openConnection();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    connection.setInstanceFollowRedirects(false);
    int code;
    try {
        code = connection.getResponseCode();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    if ((code == 301) || (code == 302) || (code == 303)) {
        String newLocation = connection.getHeaderField("Location");
        return openRemoteInputStream(Uri.parse(newLocation));
    }
    try {
        return (InputStream) finalUrl.getContent();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Drawable getDrawableFromUri(Uri uri, Context context) throws FileNotFoundException {
    InputStream inputStream = context.getContentResolver().openInputStream(uri);
    return Drawable.createFromStream(inputStream, uri.toString());
}

From source file:Main.java

public static String uriToString(Context context, Uri uri) {
    String scheme = uri.getScheme();
    if (scheme != null) {
        if (scheme.equals("http") || scheme.equals("https")) {
            return uri.toString();
        } else if (scheme.equals("content") || scheme.equals("file")) {
            Cursor cursor = context.getContentResolver().query(uri,
                    new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null);
            if (cursor.moveToNext()) {
                String name = cursor.getString(0);
                cursor.close();/*from w ww . j  av a 2  s.  c o m*/
                return name;
            }
            cursor.close();
            return uri.getPath();
        }
    }
    return uri.toString();
}

From source file:it.feio.android.omninotes.utils.BitmapHelper.java

public static Uri getThumbnailUri(Context mContext, Attachment mAttachment) {
    Uri uri = mAttachment.getUri();
    String mimeType = StorageHelper.getMimeType(uri.toString());
    if (!TextUtils.isEmpty(mimeType)) {
        String type = mimeType.split("/")[0];
        String subtype = mimeType.split("/")[1];
        switch (type) {
        case "image":
        case "video":
            // Nothing to do, bitmap will be retrieved from this
            break;
        case "audio":
            uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.drawable.play);
            break;
        default:/*ww w  .j a  v  a  2  s .  c  o  m*/
            int drawable = "x-vcard".equals(subtype) ? R.drawable.vcard : R.drawable.files;
            uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + drawable);
            break;
        }
    } else {
        uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.drawable.files);
    }
    return uri;
}

From source file:Main.java

/**
 * /*from ww  w  .j a va2  s . c o  m*/
 * @param context
 * @param uri
 *            uri of SCHEME_FILE or SCHEME_CONTENT
 * @return image path; uri will be changed to SCHEME_FILE
 */
public static String uriToImagePath(Context context, Uri uri) {
    if (context == null || uri == null) {
        return null;
    }

    String imagePath = null;
    String uriString = uri.toString();
    String uriSchema = uri.getScheme();
    if (uriSchema.equals(ContentResolver.SCHEME_FILE)) {
        imagePath = uriString.substring("file://".length());
    } else {// uriSchema.equals(ContentResolver.SCHEME_CONTENT)
        ContentResolver resolver = context.getContentResolver();
        Cursor cursor = resolver.query(uri, null, null, null, null);
        if (cursor.getCount() == 0) {
            Log.e(TAG, "Uri(" + uri.toString() + ") not found!");
            return null;
        }
        cursor.moveToFirst();
        imagePath = cursor.getString(1);
        // Change the SCHEME_CONTENT uri to the SCHEME_FILE.
        uri = Uri.fromFile(new File(imagePath));
    }
    Log.v(TAG, "Final uri: " + uri.toString());
    return imagePath;
}

From source file:Main.java

public static String buildBackDropPath(String backdrop_path) {
    Uri.Builder builder = new Uri.Builder();
    try {/*from  w  w  w  .  jav  a2  s . co  m*/
        backdrop_path = backdrop_path.substring(1);
        Uri poster_uri = builder.scheme("https").authority("image.tmdb.org").appendPath("t").appendPath("p")
                .appendPath("w1000").appendPath(backdrop_path).build();
        return poster_uri.toString();
    } catch (Exception e) {
        Log.i("Letswatch", "An error occurred " + e);
    }
    return null;
}