Discussion Forums  >  Maps, Device Location, Tracking

Replies: 4    Views: 86

WebNevees
Code is Art
Profile
Posts: 206
Reg: Oct 28, 2012
KL
11,660
05/03/13 02:38 AM (11 years ago)

Map in a customUrl screen (some offline logic)

I'm continuing a discussion from another post here that has led to a new topic. So to be relevant I thought it's best to start a new topic altogether. Original Post: https://www.buzztouch.com/forum/thread.php?tid=E6C574550BEB93E9863E6E7 So I will continue my dialogue with Smug and pickup from the last post. You might need to read the three last posts there to get in line... Ok so there's one problem here. That is offline access. Using a customURL screen with a google maps url would only work when online. So I need to check a condition with an if statement to see if we have internet access at onCreate (I'm talking android because this is where my issue lays at the moment). If not then instead of showing the lousy "Webpage not available" page and error, I want to show a picture which is a screenshot of the screen actually working. You can also think of it as being the background image but there will be no "webpage not available...." text written on it. I can include the file in the bundle (and even customize for the specific resolutions) and name it through bt_config in my screen properties. Just would neet some parameter or BOOLEAN value in the buzztouch code that might be set whenever connectivity is present. I also found the below method which I think would do if I put my code in the catch field. There is probably the best bet to 1-show the image (image of desired map, or even a working map screen screenshot) 2-somehow remove the webview so it doesn't display error information 3-add an alert saying we're not connected and you don't have live info on the map. Any ideas? So what I need is a way to check for connectivity, load an image fullscreen, and remove webview. Thanks Guys
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/03/13 03:24 AM (11 years ago)
well, keep in mind if you're using a 'webView' rather than a mapView, then it's all HTML, and you're free to include images and other text. What might work for you is to initially load the 'No Network' page, image, whatever you're going to do. Then later in your code, check for a network. If it's there, then reload your webView with the correct URL. Otherwise, the 'no network' page will appear. Keep in mind this will all happen in microseconds, so if network is available, the first page 'should not' be noticed. Otherwise you can do an if/then on the network availability, and load a page for the appropriate situation. if (isNetworkEnabled != false){ myMap.loadUrl("http://maps.google.com/maps?hl=en&f=d&q=" + smuglat + "," + smuglng); BT_debugger.showIt(activityName + ":smugUpdateLoc - Network & GPS"); }else { noNetworkPage = getCoordURL("NY"); myMap.loadData(noNetworkPage, "text/html", null); BT_debugger.showIt(activityName + ":smugUpdateLoc - No Network but GPS"); } Notice the difference between myMap.loadURL and myMap.loadData - LoadURL of course, loads a URL. 'loadData' will load text into your View. In this instance 'noNetworkPage' is a variable name for an HTML text string that pretty much lays out the 'no network available' text and graphics on a local webpage. Cheers! -- Smug
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/03/13 03:28 AM (11 years ago)
private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); BT_debugger.showIt(activityName + ":isNetworkAvailable = " + activeNetworkInfo); return activeNetworkInfo != null; } This code may not display/format completely correctly, but it's how you can test for network (either wifi or cell) for the device. The second and third line is actually "(cnntmger conntmger = (cm) getsystemsvc(context.CONN...)" all one line. Cheers! -- Smug
 
WebNevees
Code is Art
Profile
Posts: 206
Reg: Oct 28, 2012
KL
11,660
like
05/03/13 03:45 AM (11 years ago)
Thanks. On the money! I just got something of my own almost working, using this condition: sarafishirazandroid_appDelegate.rootApp.getRootDevice().getDeviceConnectionType() == "NONE" Let me check to see which one leads be to the best path.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/03/13 04:43 AM (11 years ago)
Simpler is better; anything I do might not always be the 'best' way; just the first way I found that works, lol! Cheers! -- Smug
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.