android - how does one parse the query parameters when using UriMatcher together with a ConentProvider -


i have conentprovider , make use of urimatcher perform appropriate sql statements.

the code works not way extract parameters uri's:

this failing:

string badge_id = uri.getqueryparameter("id"); string badge_value = uri.getqueryparameter("badge"); 

, , have been ideal.

what correct/optimal way parameters , have uri matcher working?

the call:

uri uri = uri.parse("content://" + usersschema.authority + "/" + usersschema.userstable.table_users + "/id/" + string.valueof(badgeid) + "/badge/" + string.valueof(badgevalue));  getapplication().getapplicationcontext().getcontentresolver().update(uri,null,null,null); 

the receiver:

    private static final int users_update_order_by_id = 1;     private static final int users_change_order_by_order = 2;     private static final int users_change_badge = 3;    urimatcher.adduri(usersschema.authority,usersschema.userstable.table_users          + "/from_id/#/to_id/#", users_update_order_by_id);    urimatcher.adduri(usersschema.authority,usersschema.userstable.table_users              + "/from_order/#/to_order/#", users_change_order_by_order);   urimatcher.adduri(usersschema.authority,usersschema.userstable.table_users              + "/id/#/badge/#", users_change_badge);    @override public int update(uri uri, contentvalues contentvalues, string selection, string[] selectionargs) {                switch (urimatcher.match(uri)) {                     case users_update_order_by_id :                         // ....                         break:                     case users_change_order_by_order:                         // ....                         break;                    case users_change_badge :                          string badge_id = uri.getqueryparameter("id");                         string badge_value = uri.getqueryparameter("badge");                          **//what better way?**                          int badge_segment = 0;                         (string segment : uri.getpathsegments()) {                             switch (badge_segment++) {                                 case  2 :                                   badge_id = segment;                                   break;                                 case 4 :                                   badge_value = segment;                                   break;                             }                         }                      break; 

looks you're confusing query parameters in traditional sense, way frameworks symfony handle them.

uri.getqueryparameter looks query string (content://demo?key=value). parameters inside path, use uri.getpathsegments().


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -