androidlicensingandroid-lvl

licence check for oreo


For new Android app updates I have to set the compileSdkversion to 26.

When I do this than I get problems with vending licency library, in the following function (ServerManagedPolicy.java) :

private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        List<**NameValuePair**> extraList = 
        **URLEncodedUtils**.parse(rawExtras, "UTF-8");
        for (**NameValuePair** item : extraList) {
            results.put(item.getName(), item.**getValue**());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data 
        from server.");
    }
    return results;
}

I know that these functions are obsolete but there is no updated version of the Android Vending Licensing library and I can nowhere find how to make it working for Oreo, or in general for versions higher than Android 19 which is the compileSdkversion I use now.

Any who can help with this?

PS. useLibrary 'org.apache.http.legacyuseLibrary 'org.apache.http.legacy is not working. The app will crash directly.


Solution

  • Try next:

    import java.net.URLDecoder;
    
    private static Map<String, String> decodeExtras(final String extras)
    {
        final Map<String, String> results = new HashMap<>();
    
        try
        {
            if (TextUtils.isEmpty(extras) == false)
            {
                final String[] pairs = extras.split("&");
    
                if (pairs.length > 0)
                {
                    for (final String pair : pairs)
                    {
                        final int index = pair.indexOf('=');
                        final String name = URLDecoder.decode(pair.substring(0, index), "UTF-8");
                        final String value = URLDecoder.decode(pair.substring(index + 1), "UTF-8");
    
                        results.put(name, value);
                    }
                }
            }
        }
        catch (UnsupportedEncodingException e)
        {
            Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
        }
    
        return results;
    }