Using the web browser to go to a list of websites

Hey all,

I need some help on this one. I want to create an app, or script, that I can input a bunch of websites. The app will then make the web browser visit each website in 60 second increments. Once it reaches the end of the list of websites, start from the beginning. I want the display to be on the entire time.

This is for my battery life tests on review phones.

This will be an Android app.

An example of how the app works:

Web browser goes to http://www.blamza.com
60 seconds passes
It then goes to www.anscamobile.com
*repeat [import]uid: 12716 topic_id: 15815 reply_id: 315815[/import]

Wow I don’t understand how this is so hard but i can’t figure it out. Here’s my code: Only the first website loads. I just want it to go blamza.com, 60 secs, anascamobile.com, 60 secs…and repeat. Any help would be appreciated
i = 0
system.setIdleTimer( false )

system.openURL( “http://www.blamza.com” )

repeat
websites()

until i == 1000

local websites = function ()
function listener1( event )
print( “listener1 called” )
system.openURL( “http://www.anscamobile.com” )

end

function listener2( event )
print( “listener2 called” )
system.openURL( “http://www.blamza.com” )

end
i = i + 1
end

timer.performWithDelay(10000, listener1)
timer.performWithDelay(20000, listener2) [import]uid: 12716 topic_id: 15815 reply_id: 58443[/import]

You want to rake up hit counters :wink:

The logical solution would be to use a WebPopup instead of system.openURL

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15815 reply_id: 58496[/import]

As I said before, its for my battery life tests. I review smartphones at my website http://www.blamza.com

Why would webpopup be the more logical choice?

More importantly how would I implement a 60 second delay between webpage loads? [import]uid: 12716 topic_id: 15815 reply_id: 58498[/import]

  1. WebPopups are run in the same context while the system.openURL is spawing a new context with the default browser on the device.

  2. This eliminates delays or switching between apps, so if you have a 1 minute gap, half the time your site might not even load on the system.openURL

With the webPopup, you can set a timer that cancels the webpopup every 60 seconds, and spawns the next site.

almost like

local listOfSites = {....}  
local nextIndex = 1  
  
local function changeSites()  
 native.cancelWebPopup()  
 native.showWebPopup(listofSites[nextIndex])  
 nextIndex = nextIndex + 1  
 if nextIndex \> maxSites then nextIndex = 1 end  
end  

that’s about it, automatic when you run the

 timer.performWithDelay(60000, changeSites, 0)  

that’s all you need to do, howzzat??

sit back and test your batteries :wink:

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15815 reply_id: 58501[/import]

Thanks for the help, I’m gonna give it a shot and report back [import]uid: 12716 topic_id: 15815 reply_id: 58506[/import]

Ok so I have this function activate when I press a button, however I am getting an error.

local webPopButtonButtonPress = function( event )  
  
listOfSites = {"http://www.blamza.com", "http://www.anscamobile.com"}  
local nextIndex = 1  
   
local function changeSites()  
 native.cancelWebPopup()  
 native.showWebPopup(listofSites[nextIndex])  
 nextIndex = nextIndex + 1  
 if nextIndex \> maxSites then nextIndex = 1 end  
end  
  
timer.performWithDelay(60000, changeSites, 0)  
  
end  

Here is the error

Runtime error
C:\Users\Savage\Desktop\website test2\main.lua:392: attempt to index glo
bal ‘listofSites’ (a nil value)
stack traceback:
[C]: ?
C:\Users\Savage\Desktop\website test2\main.lua:392: in function ‘_listen
er’
?: in function <?:446>
?: in fun

timer.performWithDelay(60000, changeSites, 0)

end [import]uid: 12716 topic_id: 15815 reply_id: 58508[/import]

Aaaaarghhh!!

I have had a typo in the camel casing…

listOfSites and listofSites

local webPopButtonButtonPress = function( event )  
  
local listOfSites = {"http://www.blamza.com", "http://www.anscamobile.com"}  
local nextIndex = 1  
local maxSites = #listOfSites  
  
local function changeSites()  
 native.cancelWebPopup()  
 native.showWebPopup(listOfSites[nextIndex])  
 nextIndex = nextIndex + 1  
 if nextIndex \> maxSites then nextIndex = 1 end  
end  
  
timer.performWithDelay(60000, changeSites, 0)  

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15815 reply_id: 58509[/import]

Testing it right now [import]uid: 12716 topic_id: 15815 reply_id: 58511[/import]

Now it looks like the webpopup activates, but it is quickly cancelled out. I want it to stay open for the 60 seconds then go to the next page.

[code]
local buttonHandler = function( event )

local listOfSites = {“http://www.blamza.com”, “http://www.anscamobile.com”}
local nextIndex = 1
local maxSites = 2

local function changeSites()
print( “listener called” )
native.cancelWebPopup()
native.showWebPopup(listOfSites[nextIndex])
nextIndex = nextIndex + 1

if nextIndex > maxSites
then nextIndex = 1
end
end

timer.performWithDelay(60000, changeSites, 0)

end

[/code] [import]uid: 12716 topic_id: 15815 reply_id: 58512[/import]

I think it may be an issue with the webpopup because I inserted system.openurl and it worked great. [import]uid: 12716 topic_id: 15815 reply_id: 58513[/import]

Anyways thanks a lot for your help, if you know how to fix the webpopup issue that would be great. [import]uid: 12716 topic_id: 15815 reply_id: 58514[/import]

that’s good, if it works for you using the system.openURL that’s fine too.

Do not have an Android with ARMv7 to test :frowning:

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15815 reply_id: 58515[/import]

I spoke too soon. The system.openurl works in the simulator but not so much on my HTC Sensation.

Any idea why webpopup would exhibit that weird behavior? [import]uid: 12716 topic_id: 15815 reply_id: 58517[/import]

Is the native.cancelWebPopup() necessary?

After removing it looks like it works on my phone [import]uid: 12716 topic_id: 15815 reply_id: 58519[/import]

try to play with the delay settings, the number 60000 and see if altering that changes anything. BTW, how could you get the webpopup showing in the simulator?? it does not work on the simulator.

The Webpopup on an Android (at least from what I remember on the older ones) is like a new page and pressing the back button brings you back to the app. Cannot comment much as I have not been working with an Android in the recent times.
cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15815 reply_id: 58520[/import]

It doesn’t work in the simulator, but i tested it on my phone. Seems to work fine thought the app is using 90 MB of RAM, doesn’t seem to be going over that though.

You are right pressing the back button brings me to the previous webpopup.

Anyways thanks a lot for your help, I really appreciate it [import]uid: 12716 topic_id: 15815 reply_id: 58521[/import]

ciaphuas,

Pressing the back key on Android causes the web popup to go back to the previously loaded page… and it will close the web popup if there is no more history. This was done to mimic Android’s built-in web browser. Some people like this behavior.

So, do you not like this behavior? Would you prefer that there be an option where the web popup ignores the back key? [import]uid: 32256 topic_id: 15815 reply_id: 59018[/import]

I’m fine with it…I was just confirming it worked [import]uid: 12716 topic_id: 15815 reply_id: 59124[/import]