Example usage for android.net Uri getPort

List of usage examples for android.net Uri getPort

Introduction

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

Prototype

public abstract int getPort();

Source Link

Document

Gets the port from the authority for this URI.

Usage

From source file:Main.java

public static int parsePort(Uri uri) {
    return uri.getPort();
}

From source file:Main.java

public static String makeSpecUrl(String inBaseUrl) {
    Uri path = Uri.parse(inBaseUrl);
    String port = path.getPort() != -1 ? ":" + String.valueOf(path.getPort()) : "";
    return path.getScheme() + "://" + path.getHost() + port + path.getPath();
}

From source file:org.fdroid.fdroid.installer.ApkCache.java

/**
 * Get the full path for where an APK URL will be downloaded into.
 *//*from  w ww  .  jav  a  2  s .  co  m*/
public static SanitizedFile getApkDownloadPath(Context context, Uri uri) {
    File dir = new File(getApkCacheDir(context), uri.getHost() + "-" + uri.getPort());
    if (!dir.exists()) {
        dir.mkdirs();
    }
    return new SanitizedFile(dir, uri.getLastPathSegment());
}

From source file:com.lemi.mario.download.utils.Proxy.java

/**
 * Return the default proxy port specified by the carrier.
 * /*w  w  w  .jav a  2 s  . c  o  m*/
 * @return The port number to be used with the proxy host or -1 if there is
 *         no proxy for this carrier.
 */
static final public int getDefaultPort() {
    String host = null;
    // use reflection to invoke the method
    try {
        Class clazz = Class.forName("android.os.SystemProperties");
        Method getMethod = clazz.getMethod("get", new Class[] { String.class });
        host = (String) getMethod.invoke(clazz, new Object[] { "net.gprs.http-proxy" });
    } catch (Exception e) {
        e.printStackTrace();
    }
    // String host = SystemProperties.get("net.gprs.http-proxy");
    if (host != null) {
        Uri u = Uri.parse(host);
        return u.getPort();
    } else {
        return -1;
    }
}

From source file:Main.java

public static String buildAccountName(Uri serverBaseUrl, String username) {
    if (serverBaseUrl.getScheme() == null) {
        serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
    }/*from   ww  w.  ja  v a 2 s  .c  om*/
    String accountName = username + "@" + serverBaseUrl.getHost();
    if (serverBaseUrl.getPort() >= 0) {
        accountName += ":" + serverBaseUrl.getPort();
    }
    return accountName;
}

From source file:Main.java

public static String buildAccountNameOld(Uri serverBaseUrl, String username) {
    if (serverBaseUrl.getScheme() == null) {
        serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
    }//  w w  w. ja v a  2 s.co m
    String accountName = username + "@" + serverBaseUrl.getHost();
    if (serverBaseUrl.getPort() >= 0) {
        accountName += ":" + serverBaseUrl.getPort();
    }
    return accountName;
}

From source file:id.nci.stm_9.FileHelper.java

/**
 * Get a file path from a Uri.//from ww  w. j a v  a  2s.c  om
 * 
 * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
 * afilechooser/utils/FileUtils.java
 * 
 * @param context
 * @param uri
 * @return
 * 
 * @author paulburke
 */
public static String getPath(Context context, Uri uri) {
    Log.d("Stm-9" + " File -",
            "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort()
                    + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost()
                    + ", Segments: " + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                return cursor.getString(column_index);
            }
        } catch (Exception e) {
            // Eat it
        }
    }

    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:org.sufficientlysecure.keychain.helper.FileHelper.java

/**
 * Get a file path from a Uri.//from   w  w w .  j a  va  2s  .  c o m
 * <p/>
 * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
 * afilechooser/utils/FileUtils.java
 *
 * @param context
 * @param uri
 * @return
 * @author paulburke
 */
public static String getPath(Context context, Uri uri) {
    Log.d(Constants.TAG + " File -",
            "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort()
                    + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost()
                    + ", Segments: " + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                int columnIndex = cursor.getColumnIndexOrThrow("_data");
                return cursor.getString(columnIndex);
            }
        } catch (Exception e) {
            // Eat it
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:org.thialfihar.android.apg.helper.FileHelper.java

/**
 * Get a file path from a Uri.//from www.j  a v  a 2 s  .  c  o  m
 *
 * from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
 * afilechooser/utils/FileUtils.java
 *
 * @param context
 * @param uri
 * @return
 *
 * @author paulburke
 */
public static String getPath(Context context, Uri uri) {
    Log.d(Constants.TAG + " File -",
            "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort()
                    + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost()
                    + ", Segments: " + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            int columnIndex = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                return cursor.getString(columnIndex);
            }
        } catch (Exception e) {
            // Eat it
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:Main.java

/**
 * Get a file path from a Uri.//from w  w  w  .ja va 2 s  .  co m
 * 
 * @param context
 * @param uri
 * @return
 * @throws URISyntaxException
 * 
 * @author paulburke
 */
public static String getPath(Context context, Uri uri) throws URISyntaxException {

    if (DEBUG)
        Log.d(TAG + " File -",
                "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: "
                        + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme()
                        + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                return cursor.getString(column_index);
            }
        } catch (Exception e) {
            // Eat it
        }
    }

    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}