Example usage for android.net Uri decode

List of usage examples for android.net Uri decode

Introduction

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

Prototype

public static String decode(String s) 

Source Link

Document

Decodes '%'-escaped octets in the given string using the UTF-8 scheme.

Usage

From source file:Main.java

public static String getAbsolutePathFromNoStandardUri(Uri mUri) {
    String filePath = null;/*w ww.  j av  a 2 s.  com*/

    String mUriString = mUri.toString();
    mUriString = Uri.decode(mUriString);

    String pre1 = "file://" + SDCARD + File.separator;
    String pre2 = "file://" + SDCARD_MNT + File.separator;

    if (mUriString.startsWith(pre1)) {
        filePath = Environment.getExternalStorageDirectory().getPath() + File.separator
                + mUriString.substring(pre1.length());
    } else if (mUriString.startsWith(pre2)) {
        filePath = Environment.getExternalStorageDirectory().getPath() + File.separator
                + mUriString.substring(pre2.length());
    }
    return filePath;
}

From source file:Main.java

public static Set<String> getQueryParameterNames(Uri uri) {
    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }/*from   w ww.  jav  a  2 s.  c o m*/

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

private static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }//from   w  ww .  j  a va 2  s . com

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }/*  ww  w .  ja  v a2 s . c  om*/

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = next == -1 ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

public static File URItoFile(String URI) {
    return new File(Uri.decode(URI).replace("file://", ""));
}

From source file:Main.java

public static final HashMap<String, String> getAllRawQueryParameters(Intent intent) {
    HashMap<String, String> queries = new HashMap<String, String>();
    if (intent != null) {
        Uri uri = intent.getData();/*from  w w w  .  j av a  2 s  .  co  m*/
        if (null != uri) {
            final String query = uri.getEncodedQuery();
            if (query != null) {
                final int length = query.length();
                int start = 0;
                do {
                    int nextAmpersand = query.indexOf('&', start);
                    int end = nextAmpersand != -1 ? nextAmpersand : length;

                    int separator = query.indexOf('=', start);
                    if (separator > end || separator == -1) {
                        separator = end;
                    }

                    String encodedKey = query.substring(start, separator);
                    String encodedValue = query.substring(separator + 1, end);

                    String key = Uri.decode(encodedKey);
                    if (!queries.containsKey(key)) {
                        queries.put(key, encodedValue);
                    }

                    // Move start to end of name.
                    if (nextAmpersand != -1) {
                        start = nextAmpersand + 1;
                    } else {
                        break;
                    }
                } while (true);
            }
        }
    }
    return queries;
}

From source file:heylee.android.network.JSONParserCustom.java

public static String autoBase64Decode(String CheckString) {
    String BASE64_REGEX = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
    if (CheckString.matches(BASE64_REGEX)) {
        if (CheckString == null || CheckString.isEmpty())
            return "";
        else// ww  w .jav a2  s . com
            return new String(Base64.decode(Uri.decode(CheckString), 0));
    }
    return CheckString;
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callMayDeepLink(WebView webView, Uri uri) {
    boolean mayDeepLink;
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null) || (webView.getContext().getPackageManager() == null)
            || (urlParam == null)) {//www  . j a va2s  .c o  m
        mayDeepLink = false;
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mayDeepLink = intent.resolveActivity(webView.getContext().getPackageManager()) != null;
    }

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_MAYDEEPLINK));
    list.add(new BasicNameValuePair("mayDeepLink", String.valueOf(mayDeepLink)));
    loadResult(webView, cb, list);
}

From source file:org.mozilla.focus.broadcastreceiver.DownloadBroadcastReceiver.java

private void displaySnackbar(final Context context, long completedDownloadReference,
        DownloadManager downloadManager) {
    if (!isFocusDownload(completedDownloadReference)) {
        return;/*from  w w w  . j a  va 2s  . co m*/
    }

    final DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(completedDownloadReference);
    try (Cursor cursor = downloadManager.query(query)) {
        if (cursor.moveToFirst()) {
            int statusColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusColumnIndex)) {
                String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));

                final String localUri = uriString.startsWith(FILE_SCHEME)
                        ? uriString.substring(FILE_SCHEME.length())
                        : uriString;
                final String fileExtension = MimeTypeMap.getFileExtensionFromUrl(localUri);
                final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
                final String fileName = URLUtil.guessFileName(Uri.decode(localUri), null, mimeType);

                final File file = new File(Uri.decode(localUri));
                final Uri uriForFile = FileProvider.getUriForFile(context,
                        BuildConfig.APPLICATION_ID + FILE_PROVIDER_EXTENSION, file);
                final Intent openFileIntent = IntentUtils.createOpenFileIntent(uriForFile, mimeType);
                showSnackbarForFilename(openFileIntent, context, fileName);
            }
        }
    }
    removeFromHashSet(completedDownloadReference);
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callDeepLink(WebView webView, Uri uri) {
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_DEEPLINK));

    if ((webView.getContext() == null) || (urlParam == null)) {
        loadResult(webView, cb, list);//ww w.j  a va  2  s  . c  o  m
        return;
    }
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        loadResult(webView, cb, list);
    }
}