Inserting a row with Android Content Provider -
i have next content provider insert row in table agenda, do:
contentvalues values = new contentvalues(1); values.put("msg", "test"); context.getcontentresolver().insert(dataprovider.content_uri_agenda, values);
and works well.
but now, i´d use uri agenda_insertwithconflict insert row. please, how can modify line :
context.getcontentresolver().insert(dataprovider.content_uri_agenda, values);
to it?
here provider:
public class dataprovider extends contentprovider { public static final string tagprovider = "net.techabout.medappointment.provider"; public static final uri content_uri_agenda = uri.parse("content://"+tagprovider+"/agenda"); public static final string table_agenda = "agenda"; private dbhelper dbhelper; private static final int agenda_allrows = 5; private static final int agenda_insertwithconflict=7; private static final urimatcher urimatcher; static { urimatcher = new urimatcher(urimatcher.no_match); urimatcher.adduri(tagprovider, "agenda", agenda_allrows); urimatcher.adduri(tagprovider, "agenda", agenda_insertwithconflict); } @override public uri insert(uri uri, contentvalues values) { sqlitedatabase db = dbhelper.getwritabledatabase(); long id; switch (urimatcher.match(uri)) { case agenda_allrows: id = db.insertorthrow(table_agenda, null, values); break; case agenda_insertwithconflict: id=db.insertwithonconflict(table_agenda, basecolumns._id, values, sqlitedatabase.conflict_replace); break; default: throw new illegalargumentexception("unsupported uri: " + uri); } uri inserturi = contenturis.withappendedid(uri, id); getcontext().getcontentresolver().notifychange(inserturi, null); return inserturi; } }
make following changes, please use naming convetions required.
// content provider static { urimatcher = new urimatcher(urimatcher.no_match); urimatcher.adduri(tagprovider, "agenda", agenda_allrows); urimatcher.adduri(tagprovider, "agenda_insert_conflicts", agenda_insertwithconflict); }
calling mechanism
string url = "net.techabout.medappointment.provider/agenda_insert_conflicts"; uri uri = uri.parse(url); context.getcontentresolver().insert(uri , values);
Comments
Post a Comment