Example usage for android.net Uri getQuery

List of usage examples for android.net Uri getQuery

Introduction

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

Prototype

@Nullable
public abstract String getQuery();

Source Link

Document

Gets the decoded query component from this URI.

Usage

From source file:com.iceteck.silicompressorr.FileUtils.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>/*from  w  w w . j  a  v  a2s .  c  om*/
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @see #isLocal(String)
 * @see #getFile(Context, Uri)
 * @author paulburke
 */
public static String getPath(final Context context, final Uri uri) {

    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());

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {

        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:org.apache.cordova.engine.crosswalk.XWalkCordovaWebViewClient.java

private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }//from www.  j av a2 s .c o  m
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch (android.os.Build.VERSION.SDK_INT) {
    case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
    case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
        return true;
    }
    return false;
}

From source file:org.totschnig.myexpenses.util.FileUtils.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>//w w  w.  j a  v  a2s.c o  m
 * Callers should only use this for display purposes and not for accessing the file directly via the
 * file system
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @see #isLocal(String)
 * @see #getFile(Context, Uri)
 * @author paulburke
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {

    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());

    // DocumentProvider
    if (isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                String path = Environment.getExternalStorageDirectory().getPath();
                if (split.length > 1) {
                    path += "/" + split[1];
                }
                return path;
            }
            //there is no documented way of returning a path to a file on non primary storage.
            //so what we do is displaying the documentId to the user which is better than just null
            return docId;
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.bbxiaoqu.api.util.Utils.java

/**
 * ???/*from  w  ww .j av a 2s  . c om*/
 */
public static HashMap<String, String> parserUri(Uri uri) {
    HashMap<String, String> parameters = new HashMap<String, String>();
    String paras[] = uri.getQuery().split("&");
    for (String s : paras) {
        if (s.indexOf("=") != -1) {
            String[] item = s.split("=");
            parameters.put(item[0], item[1]);
        } else {
            return null;
        }
    }
    return parameters;
}

From source file:fpt.isc.nshreport.utilities.FileUtils.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>/*w  w  w  . j a v a 2s. c  o m*/
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 *
 * @param context The context.
 * @param uri     The Uri to query.
 * @author paulburke
 * @see #isLocal(String)
 * @see #getFile(Context, Uri)
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {

    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());

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // LocalStorageProvider
        //if (isLocalStorageDocument(uri)) {
        if (false) {
            // The path is the id
            return DocumentsContract.getDocumentId(uri);
        }
        // ExternalStorageProvider
        else if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.HttpMetaEchoFilter.java

@Override
public void handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback,
        ServiceFilterResponseCallback responseCallback) {

    JsonObject jResponse = new JsonObject();

    jResponse.addProperty("method", request.getMethod());

    Header[] headers = request.getHeaders();
    if (headers != null && headers.length > 0) {
        JsonObject jHeaders = new JsonObject();

        for (Header header : headers) {
            jHeaders.addProperty(header.getName(), header.getValue());
        }/*w ww  .  ja va  2  s.c  o m*/

        jResponse.add("headers", jHeaders);
    }

    Uri uri = Uri.parse(request.getUrl());
    String query = uri.getQuery();

    if (query != null && query.trim() != "") {
        JsonObject jParameters = new JsonObject();

        for (String parameter : query.split("&")) {
            jParameters.addProperty(parameter.split("=")[0], parameter.split("=")[1]);
        }
        jResponse.add("parameters", jParameters);
    }

    ServiceFilterResponseMock response = new ServiceFilterResponseMock();
    response.setContent(jResponse.toString());
    response.setStatus(new StatusLineMock(200));

    responseCallback.onResponse(response, null);
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.framework.filters.HttpMetaEchoFilter.java

@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
        NextServiceFilterCallback nextServiceFilterCallback) {

    JsonObject jResponse = new JsonObject();

    jResponse.addProperty("method", request.getMethod());

    Header[] headers = request.getHeaders();
    if (headers != null && headers.length > 0) {
        JsonObject jHeaders = new JsonObject();

        for (Header header : headers) {
            jHeaders.addProperty(header.getName(), header.getValue());
        }/* ww w  . ja va2s  . com*/

        jResponse.add("headers", jHeaders);
    }

    Uri uri = Uri.parse(request.getUrl());
    String query = uri.getQuery();

    if (query != null && query.trim() != "") {
        JsonObject jParameters = new JsonObject();

        for (String parameter : query.split("&")) {
            jParameters.addProperty(parameter.split("=")[0], parameter.split("=")[1]);
        }
        jResponse.add("parameters", jParameters);
    }

    ServiceFilterResponseMock response = new ServiceFilterResponseMock();
    response.setContent(jResponse.toString());
    response.setStatus(new StatusLineMock(200));

    ServiceFilterRequestMock requestMock = new ServiceFilterRequestMock(response);
    return nextServiceFilterCallback.onNext(requestMock);

    //return nextServiceFilterCallback.onNext(request);
}

From source file:com.applozic.mobicommons.file.FileUtils.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>/*from w w w .ja  v a2s.c  o m*/
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 *
 * @param context The context.
 * @param uri     The Uri to query.
 * @author paulburke
 * @see #isLocal(String)
 * @see #getFile(android.content.Context, android.net.Uri)
 */

public static String getPath(final Context context, final Uri uri) {

    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());

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // LocalStorageProvider
        if (isLocalStorageDocument(uri)) {
            // The path is the id
            return DocumentsContract.getDocumentId(uri);
        }
        // ExternalStorageProvider
        else if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.dvdprime.mobile.android.ui.FlickrOauthActivity.java

@Override
public void onResume() {
    super.onResume();

    String scheme = getIntent().getScheme();
    // Flickr Oauth
    oauth = getOAuthToken();/*from w  w  w .j a v  a 2 s.  co m*/
    if (Constants.ID_SCHEME.equals(scheme) && (oauth == null || oauth.getUser() == null)) {
        Uri uri = getIntent().getData();
        String query = uri.getQuery();
        LOGD(TAG, "Returned Query: " + query);
        String[] data = query.split("&");
        if (data != null && data.length == 2) {
            String oauthToken = data[0].substring(data[0].indexOf("=") + 1);
            String oauthVerifier = data[1].substring(data[1].indexOf("=") + 1);
            LOGD(TAG, StringUtil.format("OAuth Token: {0}; OAuth Verifier: {1}", oauthToken, oauthVerifier));

            String secret = PrefUtil.getInstance().getString(PrefKeys.FLICKR_API_TOKEN_SECRET, null);
            if (secret != null) {
                GetOAuthTokenTask task = new GetOAuthTokenTask(this);
                task.execute(oauthToken, secret, oauthVerifier);
            }
        }
    }
}

From source file:com.facebook.internal.FacebookWebFallbackDialog.java

@Override
protected Bundle parseResponseUri(String url) {
    Uri responseUri = Uri.parse(url);
    Bundle queryParams = Utility.parseUrlQueryString(responseUri.getQuery());

    // Convert Bridge args to the format that the Native dialog code understands.
    String bridgeArgsJSONString = queryParams.getString(ServerProtocol.FALLBACK_DIALOG_PARAM_BRIDGE_ARGS);
    queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_BRIDGE_ARGS);

    if (!Utility.isNullOrEmpty(bridgeArgsJSONString)) {
        Bundle bridgeArgs;//from  w  w w. j  av a2  s  .  com
        try {
            JSONObject bridgeArgsJSON = new JSONObject(bridgeArgsJSONString);
            bridgeArgs = BundleJSONConverter.convertToBundle(bridgeArgsJSON);
            queryParams.putBundle(NativeProtocol.EXTRA_PROTOCOL_BRIDGE_ARGS, bridgeArgs);
        } catch (JSONException je) {
            Utility.logd(TAG, "Unable to parse bridge_args JSON", je);
        }
    }

    // Convert Method results to the format that the Native dialog code understands.
    String methodResultsJSONString = queryParams.getString(ServerProtocol.FALLBACK_DIALOG_PARAM_METHOD_RESULTS);
    queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_METHOD_RESULTS);

    if (!Utility.isNullOrEmpty(methodResultsJSONString)) {
        methodResultsJSONString = Utility.isNullOrEmpty(methodResultsJSONString) ? "{}"
                : methodResultsJSONString;
        Bundle methodResults;
        try {
            JSONObject methodArgsJSON = new JSONObject(methodResultsJSONString);
            methodResults = BundleJSONConverter.convertToBundle(methodArgsJSON);
            queryParams.putBundle(NativeProtocol.EXTRA_PROTOCOL_METHOD_RESULTS, methodResults);
        } catch (JSONException je) {
            Utility.logd(TAG, "Unable to parse bridge_args JSON", je);
        }
    }

    // The web host does not send a numeric version back. Put the latest known version in there so NativeProtocol
    // can continue parsing the response.
    queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_VERSION);
    queryParams.putInt(NativeProtocol.EXTRA_PROTOCOL_VERSION, NativeProtocol.getLatestKnownVersion());

    return queryParams;
}