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:org.prx.playerhater.util.PlaylistParser.java

public static Uri[] parsePlaylist(Uri uri) {
    try {//w  w w.ja  va2s .  c  o m
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpHead(uri.toString()));
        Header contentType = response.getEntity().getContentType();
        if (contentType != null) {
            String mimeType = contentType.getValue().split(";")[0].trim();

            for (String plsMimeType : PLS_MIME_TYPES) {
                if (plsMimeType.equalsIgnoreCase(mimeType)) {
                    return parsePls(uri);
                }
            }

            for (String m3uMimeType : M3U_MIME_TYPES) {
                if (m3uMimeType.equalsIgnoreCase(mimeType)) {
                    return parseM3u(uri);
                }
            }
        }
    } catch (Exception e) {
    }
    return new Uri[] { uri };
}

From source file:Main.java

public static Bitmap getIconBitmap(Context mContext, String path) {
    Bitmap bmp;//  ww  w  .  j  a v a  2  s .  com

    try {
        Uri uri = getUri(mContext, path);
        if (uri == null)
            return null;
        else
            uri = Uri.parse(uri.toString());
        bmp = getIconFromUri(mContext, uri);
    } catch (IOException e) {
        bmp = null;
    }

    return bmp;
}

From source file:org.prx.playerhater.util.PlaylistParser.java

private static Uri[] parseM3u(Uri uri) {

    try {//from  www.  j  av a  2s.co  m
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
        HttpEntity entity = response.getEntity();
        InputStream inputStream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        ArrayList<Uri> uriList = new ArrayList<Uri>();
        do {
            line = reader.readLine();
            if (line != null) {
                if (!line.startsWith("#")) {
                    uriList.add(Uri.parse(line.trim()));
                }
            }
        } while (line != null);
        if (uriList.size() > 0) {
            Uri[] res = new Uri[uriList.size()];
            return uriList.toArray(res);
        }
    } catch (Exception e) {

    }
    return new Uri[] { uri };
}

From source file:org.prx.playerhater.util.PlaylistParser.java

private static Uri[] parsePls(Uri uri) {
    try {//from   w w  w. j  ava 2s  . c  o m
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
        HttpEntity entity = response.getEntity();
        InputStream inputStream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String header = reader.readLine();
        if (header.trim().equalsIgnoreCase("[playlist]")) {
            String line;
            ArrayList<Uri> uriList = new ArrayList<Uri>();
            do {
                line = reader.readLine();
                if (line != null) {
                    if (line.startsWith("File")) {
                        String fileName = line.substring(line.indexOf("=") + 1).trim();
                        uriList.add(Uri.parse(fileName));
                    }
                }
            } while (line != null);
            if (uriList.size() > 0) {
                Uri[] res = new Uri[uriList.size()];
                return uriList.toArray(res);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new Uri[] { uri };
}

From source file:Main.java

public static boolean isOnlineVideo(Uri uri) {
    if (uri == null) {
        return false;
    }//w w  w.j  a  v  a 2 s  .c  o m
    String scheme = uri.getScheme();
    if (scheme != null && (scheme.equals("http") || scheme.equals("https") || scheme.equals("rtsp"))) {
        return true;
    }
    String path = uri.toString();
    if (path != null && path.contains("app_smb")) {
        return true;
    }
    return false;
}

From source file:fr.free.nrw.commons.Utils.java

/**
 * Opens Custom Tab Activity with in-app browser for the specified URL.
 * Launches intent for web URL//w ww. j  a  va  2 s.  c  o m
 * @param context
 * @param url
 */
public static void handleWebUrl(Context context, Uri url) {
    Timber.d("Launching web url %s", url.toString());
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
    if (browserIntent.resolveActivity(context.getPackageManager()) == null) {
        Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT);
        toast.show();
        return;
    }

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor));
    builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
    builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    CustomTabsIntent customTabsIntent = builder.build();
    // Clear previous browser tasks, so that back/exit buttons work as intended.
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    customTabsIntent.launchUrl(context, url);
}

From source file:com.microsoft.azure.engagement.unity.EngagementWrapper.java

public static void setAndroidActivity(Activity _androidActivity) {

    androidActivity = _androidActivity;/*from   ww  w .  j a v a2s  . c o m*/
    Uri data = _androidActivity.getIntent().getData();
    if (data != null) {
        String lastUrl = data.toString();
        handleOpenURL(lastUrl);
    }
}

From source file:Main.java

public static void addCallLog(Context context, ContentValues values, ContentValues extraValues) {
    ContentResolver contentResolver = context.getContentResolver();
    Uri result = contentResolver.insert(CallLog.Calls.CONTENT_URI, values);

    if (result != null) {
        // Announce that to other apps
        final Intent broadcast = new Intent(ACTION_ANNOUNCE_SIP_CALLLOG);
        broadcast.putExtra(EXTRA_CALL_LOG_URI, result.toString());
        String provider = extraValues.getAsString(EXTRA_SIP_PROVIDER);
        if (provider != null) {
            broadcast.putExtra(EXTRA_SIP_PROVIDER, provider);
        }//  ww  w . j  a v a 2 s  .c o m
        context.sendBroadcast(broadcast);
    }
}

From source file:Main.java

/**
 * Set a shared preference for an Uri.//ww w  . j a va 2s.  c o  m
 *
 * @param preferenceId the id of the shared preference.
 * @param uri          the target value of the preference.
 */
public static void setSharedPreferenceUri(final int preferenceId, @Nullable final Uri uri) {
    SharedPreferences.Editor editor = getSharedPreferences().edit();
    if (uri == null) {
        editor.putString(applicationContext.getString(preferenceId), null);
    } else {
        editor.putString(applicationContext.getString(preferenceId), uri.toString());
    }
    editor.apply();
}

From source file:com.appdynamics.demo.gasp.service.RESTIntentService.java

private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) {
    try {// w  ww. j a  v  a 2s.c  o  m
        if (params == null) {
            request.setURI(new URI(uri.toString()));
        } else {
            Uri.Builder uriBuilder = uri.buildUpon();

            // Loop through our params and append them to the Uri.
            for (BasicNameValuePair param : paramsToList(params)) {
                uriBuilder.appendQueryParameter(param.getName(), param.getValue());
            }

            uri = uriBuilder.build();
            request.setURI(new URI(uri.toString()));
        }
    } catch (URISyntaxException e) {
        Log.e(TAG, "URI syntax was incorrect: " + uri.toString(), e);
    }
}