android - Muzei database doesn't update when I update external JSON -
i'm in middle of making wallpaper app android , i'm have problem muzei support , hoping here can me see i'm missing.
i have json file app uses wallpaper urls , display pictures from. works fine , gets right images. if update json more entries , more images muzei extension still uses old database. thinking maybe caches database , doesn't update whatever reason. way use updated json file clear data of app , set different extension in muzei , reset muzei extension. not user friendly.
probably being blind appreciated.
artsource.java:
package com.main.walls.muzei; import android.content.intent; import android.net.uri; import android.util.log; import com.google.android.apps.muzei.api.artwork; import com.google.android.apps.muzei.api.remotemuzeiartsource; import com.google.android.apps.muzei.api.usercommand; import com.main.walls.utilities.preferences; import org.apache.http.httpresponse; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.util.entityutils; import org.json.jsonarray; import org.json.jsonobject; import java.util.arraylist; import java.util.random; import walls.wallpaper.r; public class artsource extends remotemuzeiartsource { private wallsdatabase wdb; private arraylist<wallpaperinfo> wallslist; private preferences mprefs; private static final string artsource_name = "walls"; private static final string json_url = "http://pastebin.com/raw.php?i=vwtzhj0n"; private static final string market_url = "https://play.google.com/store/apps/details?id="; private static final int command_id_share = 1337; public artsource() { super(artsource_name); } @override public int onstartcommand(intent intent, int flags, int startid) { string command = intent.getextras().getstring("service"); if (command != null) { try { ontryupdate(update_reason_user_next); } catch (retryexception e) { log.d("muzeiartsource", log.getstacktracestring(e)); } } return super.onstartcommand(intent, flags, startid); } @override public void oncreate() { super.oncreate(); wdb = new wallsdatabase(getapplicationcontext()); wallslist = new arraylist<>(); mprefs = new preferences(artsource.this); arraylist<usercommand> commands = new arraylist<>(); commands.add(new usercommand(builtin_command_id_next_artwork)); commands.add(new usercommand(command_id_share, getstring(r.string.justshare))); setusercommands(commands); } @override public void oncustomcommand(int id) { super.oncustomcommand(id); if (id == command_id_share) { artwork currentartwork = getcurrentartwork(); intent sharewall = new intent(intent.action_send); sharewall.settype("text/plain"); string authorname = currentartwork.getbyline(); string storeurl = market_url + getresources().getstring(r.string.package_name); string iconpackname = getstring(r.string.app_name); sharewall.putextra(intent.extra_text, getstring(r.string.partone) + authorname + getstring(r.string.parttwo) + iconpackname + getstring(r.string.partthree) + storeurl); sharewall = intent.createchooser(sharewall, getstring(r.string.share_title)); sharewall.addflags(intent.flag_activity_new_task); startactivity(sharewall); } } @override protected void ontryupdate(int reason) throws retryexception { if (mprefs.isfeaturesenabled()) { if (wallslist.size() == 0) getwallpapersfromurl(json_url); int = getrandomint(); string token = wallslist.get(i).getwallurl(); publishartwork(new artwork.builder() .byline(wallslist.get(i).getwallauthor()) .imageuri(uri.parse(wallslist.get(i).getwallurl())) .token(token) .viewintent(new intent(intent.action_view, uri.parse(wallslist.get(i).getwallurl()))) .build()); scheduleupdate(system.currenttimemillis() + mprefs.getrotatetime()); } } private int getrandomint() { return new random().nextint(wallslist.size()); } private void getwallpapersfromurl(string url) { wallslist.clear(); wallslist = wdb.getallwalls(); if (wallslist.size() == 0) { try { httpclient cl = new defaulthttpclient(); httpresponse response = cl.execute(new httpget(url)); if (response.getstatusline().getstatuscode() == 200) { final string data = entityutils.tostring(response.getentity()); jsonobject jsonobject = new jsonobject(data); final jsonarray jsonarray = jsonobject.getjsonarray("wallpapers"); wallslist.clear(); wdb.deleteallwallpapers(); (int = 0; < jsonarray.length(); i++) { jsonobject = jsonarray.getjsonobject(i); wallpaperinfo jsondata = new wallpaperinfo( jsonobject.getstring("author"), jsonobject.getstring("url") ); wdb.addwallpaper(jsondata); wallslist.add(jsondata); } } } catch (exception e) { log.d("wallpapers", log.getstacktracestring(e)); } } } }
not sure if need other code in here or not , logcat doesn't anything, it's though it's it's working normal. if need see more code let me know.
thanks help.
basically right , being stupid , missing simplest thing, didn't have artsource.java.
in wallsdatabase.java wasn't updating database_version. leaving @ 1 , when updated app didn't bother update database because version same.
so change value of private static final int database_version = 1
higher number , should work great.
simple mistake easy 1 make guess.
Comments
Post a Comment