[Q] Problem with WebView caching result - Android Software Development

Hey all,
This problem has been killing me for a few days, I've tried searching the web and so far I've come up with not much.
I've got a widget which uses a WebView to load a page from a URL and read the contents of the page. The reason for the WebView is that I need to emulate the browser in order to get the page to display the content, a HttpGet won't get it back (reliably).
None the less, at some point the WebView stops loading new content and appears to keep loading a cached page instead. In the code it appears to have gone to the web to get a new page but what is returned is old data.
Those with the Android 2.2 build get a new button for applications in the settings area which allows them to clear the App Data. Doing this blows away whatever cached data the WebView is using and it starts to work again.
So what I would like to do is programmatically blow this App Data away. Only problem is that I have no idea what data it is. I'm not explicitly make it anywhere in my app, the WebView control appears to be making it itself. Would anyone know what is going on here and how I can avoid it?
I've turned all caching off (in every way), it had no effect.
Code:
browser = new WebView(context);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
browser.setDrawingCacheEnabled(false);
browser.clearCache(true);
browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
browser.setWebViewClient(new TelstraWebViewClient());
browser.loadUrl(URL);
Cheers

Related

Help with WebView - loading files locally

I have a problem. I want to create a screen where a map (a picture) will be displayed, with some interaction (dragging, zoom, etc).
I started with creating an ImageView, but I found out that those gestures are still quite complicated to implement (couldn't find a single example that I could work with). Then, someone suggested me that I could use a WebView instead, as it would act as a workaround to those gesture issues. Indeed, switching to WebView did solve some of my problems.
However, I do have a new problem derived from this. As of now, to display the image, the terminal requires an internet connection; I've found out how to load files locally, but only if they're on the terminal itself (as in if the file is on the sdcard). Is there any way to access the image without having to store it separately from the program? Like when accessing the drawables?
Sorry if this a basic question, I'm pretty much starting and the amount of tutorials/information available is either dated or confusing. Btw, I'm developing on Froyo.

[Q] Android app auto starts again when device rotated

Hello all,
I've written a simple audio player app and testing it in Samsung Galaxy S.
It is a simple app with can create playlist and some buttons to play the mp3 file.
However, there's a funny bug in it.
After starting the app, whenever I rotate the phone, the running app will launch another instance of the app. If I rotate again, another instance (3rd) would be started. So u can hear 3 copies of the same audio being played simultaneously.
What could be wrong with it?
Is there some code which can prevent program re-entry?
Thanks.
It's not a bug, that's the way andorid OS works. You need to account for this in OnCreate for your activity. I assume you are spawning off the actual playing of the MP3 in a thread or service. You need to check if the service is already running in OnCreate and attach, else spawn a new one.
Hello Gene,
How do I check if an activity is already running?
I could not find the answer on the android developer page (the topic on application fundamentals).
And no, I'm not converting it to a service yet as this is my first app.
Haven't explore service yet.
Thanks.
I read on another article, a simple way to prevent this is to add overwrite the onConfigurationChanged function
@Override
public void onConfigurationChanged(Configuration newConfig) {
//ignore orientation change
super.onConfigurationChanged(newConfig);
}
and modify the androidmanifest.xml
<activity android:name="selectCategories" android:configChanges="orientation|keyboardHidden"></activity>
But it still launch multiple instance of the app.
Thanks.
This is a good question and should be in an FAQ somewhere.
As already mentioned, changing the display orientation basically restarts your app. Read the Android dev page on Activity lifecycle for more info.
A short answer for your question is: the Bundle parameter for onCreate() will be null when your app is first run. When your app is paused and restarted, that Bundle will be non-null. You can store data in that Bundle by overriding onSaveInstanceState(), then check for that data in onCreate(). It's a good idea to learn how to do this (save/read app data on pause/restart). Once you start testing apps by rotating the display at various times, you'll find a lot of them FC at unexpected places.
This is indeed a topic that keeps surprising people who are new to android (ahem, like me 4-5 months ago ).
The solutions above are perfect, however in certain situations there's another trick that might make your life much easier. I suspect it won't help you in this case, but it might help others who tackle the problem and see this thread.
Certain applications, mainly games, should be fixed in a single orientation. I.E. you won't be playing angry birds on portrait - that game is locked to landscape, as it should be. In order to lock your activity in a certain orientation you add this attribute to the manifest under the Activity tag. So a standard activity might look something like that, combined with the ignore tag from the previous posts:
Code:
<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:name="whatever">
The great thing about this combination is that your activity will not restart at all when the phone is rotated. Of course, for a standard activity you'd usually want to support both landscape and portrait, but if you need your app to be in a fixed orientation this is the way to go - no weird FCs or annoying bugs
Hi,
How do I check the bundle?
And also, what to do if the bundle is not null? Just return?
Thanks.
regards
r_p_ang said:
This is a good question and should be in an FAQ somewhere.
As already mentioned, changing the display orientation basically restarts your app. Read the Android dev page on Activity lifecycle for more info.
A short answer for your question is: the Bundle parameter for onCreate() will be null when your app is first run. When your app is paused and restarted, that Bundle will be non-null. You can store data in that Bundle by overriding onSaveInstanceState(), then check for that data in onCreate(). It's a good idea to learn how to do this (save/read app data on pause/restart). Once you start testing apps by rotating the display at various times, you'll find a lot of them FC at unexpected places.
Click to expand...
Click to collapse

IMDB full screen trailers

Hi all
I'm having some issues with watching trailers at imdb.com.
I'm using IE10 and have no full screen option.
When using Chrome, there is one.
I've noticed that if I'm going to IE10 dev option (F12) and there I'm changing the user agent to Chrome, I have the full screen option and actually and IE crashes a lot less (I don't understand why, but it does).
Every time I'm closing IE, the option resets the default setting and I have to manually change it to Chrome again.
I'm searching of a way to set the user agent of IE10 (Win8 Pro x64) to be always on "Chrome Mode"
Is there a way to do it?
Thanks
*grumble grumble ****ty web developers sending ****ty code to anything with MSIE in the user agent string and ****ing up the browsing experience of their customers grumble mutter grumble*
I don't know of a way off-hand, although there used to be a way in the registry to set the default IE user-agent string; that *might* still work. Alternatively, you can just never close the browser. I'm serious - it's one of the first things I open when I start the PC, one of the last things I close when rebooting, and I reboot as little as possible. Close extra tabs if you're worried about RAM usage, but if you've got enough RAM even that isn't important. I regularly have 20-30 tabs open for weeks.

[Q] Nook Simple Touch disable screensaver & full screen browser

Hi,
First of all, thanks for great set of resources! I was rooted an up and running with market in no time.
I am planning to use the Nook as a home automation controller, where the interface is presented through a webpage. For that, I am going to have it mounted and constantly powered-up.
So, my question is - how can I disable screensaver to have the Nook show the browser 24/7?
Also, is there any simple way to show contexts of the browser window without the navigation buttons? (If not, no worries - I can put something together quickly in PhoneGap or similar).
Thanks!
Bumping for interest - has OP/anyone found a solution to this? I'm going to have a tinker with the sys files in the next few days to see if I can manipulate those, will post any positive results.
I'm looking for always-on functionality as part of a live bus timetable / weather station project I'm 75% through.
For those interested, I'm running a simple PHP server pulling data from London's TFL API and the UK MetOffice's Datapoint API and displaying the page in Dolphin.
julianfox said:
Bumping for interest - has OP/anyone found a solution to this? I'm going to have a tinker with the sys files in the next few days to see if I can manipulate those, will post any positive results.
I'm looking for always-on functionality as part of a live bus timetable / weather station project I'm 75% through.
For those interested, I'm running a simple PHP server pulling data from London's TFL API and the UK MetOffice's Datapoint API and displaying the page in Dolphin.
Click to expand...
Click to collapse
http://forum.xda-developers.com/showthread.php?p=29113425 (found by googling "nook screensaver disable sqlite3").
julianfox said:
Bumping for interest - has OP/anyone found a solution to this? I'm going to have a tinker with the sys files in the next few days to see if I can manipulate those, will post any positive results.
I'm looking for always-on functionality as part of a live bus timetable / weather station project I'm 75% through.
For those interested, I'm running a simple PHP server pulling data from London's TFL API and the UK MetOffice's Datapoint API and displaying the page in Dolphin.
Click to expand...
Click to collapse
Hi, I am quite interested in your project and was wondering how you got on with this.
Basically I am looking to have a calendar + weather page up constantly on in my rooted Nook Simple Touch. I have managed to get rid of the screensaver but it still goes into sleep mode after a while. Also would like to get some direction on how I could do my own PHP based page because most of the calendar apps out there dont seem to report weather
Jayyzee said:
Hi, I am quite interested in your project and was wondering how you got on with this.
Basically I am looking to have a calendar + weather page up constantly on in my rooted Nook Simple Touch. I have managed to get rid of the screensaver but it still goes into sleep mode after a while. Also would like to get some direction on how I could do my own PHP based page because most of the calendar apps out there dont seem to report weather
Click to expand...
Click to collapse
I implemented the server side part of this weather app
http://www.mpetroff.net/archives/2012/09/14/kindle-weather-display/
also made the following changes
http://www.shatteredhaven.com/2012/11/1347365-kindle-weather-display.html
Getting the image on the nook is a different story. I tried using crond to wget or curl the image from the server to the screensaver folder so I could have other info graphics rotated throughout the day. I was unable to get the image via wget and unable to get cron working. Any suggestions... (besides having a browser open 247)
here is another example
http://origami.phys.rpi.edu/~jimenc/public/pjs/weather_kindle/server2/weather.php
Refresh?
larryflynt said:
Getting the image on the nook is a different story. I tried using crond to wget or curl the image from the server to the screensaver folder so I could have other info graphics rotated throughout the day. I was unable to get the image via wget and unable to get cron working. Any suggestions... (besides having a browser open 247)
Click to expand...
Click to collapse
Hi, kudos for the progress so far.
I take it you couldn't just use another device to FTP the file to the nook every so often?
I was hoping to do a very similar thing with my spare NST but unfortunately my coding skills are not up to that level. You mention that you were trying to populate the screensaver folder with the image to be displayed, would there be any way to automatically make the NST wake up every few hours to refresh this image (assuming you can get the image there in the first place)?
I think that the better way to do this all is to write an app.
The app could use either an ImageView or a WebView.
You could easily make this work directly without a proxy or a server.
You wouldn't have to play around with screen timeout/wakeup,
This is going to be hard wired powered?
Renate NST said:
I think that the better way to do this all is to write an app.
The app could use either an ImageView or a WebView.
You could easily make this work directly without a proxy or a server.
You wouldn't have to play around with screen timeout/wakeup,
This is going to be hard wired powered?
Click to expand...
Click to collapse
The more I think about this, the nook simple touch might have to be charging.
I've done something very similar with my nook showing a custom weather listing in a fullscreen Dolphin browser. Though I have a problem with it not running for more than a day or so before the browser stops refreshing anymore. Have you experienced this? I'm currently looking into some way to kill/restart the browser on schedule perhaps.
Also, how did you get the browser in landscape mode? I can't find that anywhere.
neonpolaris said:
Also, how did you get the browser in landscape mode? I can't find that anywhere.
Click to expand...
Click to collapse
I use this to set the orientation: https://play.google.com/store/apps/details?id=com.mah.screenrotationlock
OB
Sent from my HTCEVOV4G using Tapatalk 2
Another way to set orientation is if you have an application that only does landscape.
Switch to the landscape app, home out of that, go to the application that does both.
It should stay in landscape mode.
I have an assortment of apps, some portrait only, some landscape only, some both orientations.
By jumping briefly to a landscape only or portrait only app you can set the orientation for subsequent apps.
Thanks for the help guys!
I've got a web server running on my NAS serving a custom page for me. The browser launches fullscreen on boot up via some auto start app. After 5 min, the page redirects to an all black page for a second, then an all white page for a second (to clean up the display), then back to the original page with any new information on it.
This works well except for two issues.
1. On boot up, there's no way to avoid the first lock screen. After unlocked, it doesn't come back, but it's always there on startup. This wouldn't really be an issue except...
2. The browser stops loading the page after a while. I can hit refresh and it goes through the motions, but the page isn't updated. It can take a couple of days for this to happen. Restarting the nook solves this. I confirmed that the page is still served normally to other devices (not a web server problem). I would just have the device auto restart at 3am or something, but then the lock screen would always be there.
Do you guys have any ideas about how to correct this or at least work around it?
I can't even try other browsers because this is the only one I've found that displays full screen.
Any updates on this?
I wonder if there's a way to have a cron job kill and relaunch the browser every once in a while to get past the freezing issue you'd mentioned. Or just have the cron job kill the browser every once in a while and relaunch it, pointed at a new information display page.
Even better would be if there was way to bypass the need for a web browser and interact directly with the e-ink screen buffer as can be done on rooted kindle devices. (I can't post a link, but google search "Tools Eink Framebuffer Update Trigger" to find the kindle framebuffer commands)
Yeah, I worked directly with the screen output on my kobo, which worked well, but it was more of a pain to make changes. That might be because I'm more familiar with php and css than python and screen blit-ing. Having android to work with makes it much easier to expand functionality by just downloading an app and using my fingers, instead compiling software and ssh-ing in for everything.
Speaking of which, it looks like my problem is solved. I installed tasker and set it to kill the browser at 3am and start the browser at 3:01am. Thanks all.
What about google play apps for weather? Most of the apps I have used so far have had contrast issues since they are designed for color screens. Does anybody know of good apps that display the current weather info and forcast data in an eink friendly color scheme?
As far as the going to sleep issue, the apk listed in the second comment here: http://forum.xda-developers.com/nook-touch/general/fridge-calendar-t3057759
worked without issue for me, so that problem has mostly been solved.
Try this: electricsign app
Apologies for the resurrection, but for those looking for a digital low power / e-ink info display this might just do it.
This app will do the trick if a static jpg of a web page updated at an interval will do (set to output a jpeg in the custom screensaver folder on rooted nook)
Electricsign android app: (search electricsign on the play store - I can't post a URL here yet).
Leave the WiFi on and set the screensaver timeout.
The source code is on github also (google.it ).
I can never find the app because I always think it's called electricsheep.
Hope this helps someone...or me in the future.
Hi future me, the app is called electricsign, not electricsheep. You'll thank me next time you forget. From your past self bored at a ceildh BC your gf doesn't want to dance.
electricsign looks like the ticket!

Help with android 12 tv box T95Z PLUS

i need help with it i need to customize it,
first i want it to to luch a browser in especific url and in full screen after android boots even when looses power and comes back on i want to to show that specific page, also if is posible to customize the system to show my own logo when is booting. but most important thing is to have it launch a browser in automaticly after it boots on its own and go into full screen even if the browser gets refresh the reason im seying refesh is because i have an autoreflesh javascript on the website that i want to display from a web server, can some one help me out. i currently found that TV BRO Browser allows me to stay in full screen, even if it refreshes that awesome, but i want to be able to have the browser to download the web content, so even when the box looses internet still displays the content. please help me out
AXEngine said:
i need help with it i need to customize it,
first i want it to to luch a browser in especific url and in full screen after android boots even when looses power and comes back on i want to to show that specific page, also if is posible to customize the system to show my own logo when is booting. but most important thing is to have it launch a browser in automaticly after it boots on its own and go into full screen even if the browser gets refresh the reason im seying refesh is because i have an autoreflesh javascript on the website that i want to display from a web server, can some one help me out. i currently found that TV BRO Browser allows me to stay in full screen, even if it refreshes that awesome, but i want to be able to have the browser to download the web content, so even when the box looses internet still displays the content. please help me out
Click to expand...
Click to collapse
why all this complication?
it's way easier to develop an app that auto-starts on bootup, which opens your website in full screen and auto refresh every xx days, hours, minutes or even seconds.
how do you think most apps example like costco, ISPs, Banking apps work? 99% of them are apps that open their website which is optimized for mobile devices, so you can only navigate through that specific site.
I'm sure there are some android app developers here in xda that can do this for you in no time

Categories

Resources