For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 4 replies, 3 voices, and was last updated 13 years, 4 months ago by
support-octavio.
-
AuthorPosts
-
hardsofftMemberi’m designing a native app named as internet that uses some web links. i used the below code. while i am testing on my iphone it says
when no network : internet.html – no connection
when wifi : internet.html – wifi , etcnow my problem is that i dont need my app name internet.html to be displayed on screen (just No Connection or wi-fi or 3G, etc ) and when there is no network connection my app button needs to be disabled( user wouldn’t be able to push button). The below code works only once, if it needs to work each time we need to close app by double clicking home button. but i need a code to work without closing the app.
CODE:
phoneui.documentReadyHandler = function()
{
document.addEventListener(“deviceready”, onDeviceReady, false);}
function onDeviceReady()
{
checkConnection();
}function checkConnection()
{
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = ‘Unknown connection’;
states[Connection.ETHERNET] = ‘Ethernet connection’;
states[Connection.WIFI] = ‘WiFi connection’;
states[Connection.CELL_2G] = ‘Cell 2G connection’;
states[Connection.CELL_3G] = ‘Cell 3G connection’;
states[Connection.CELL_4G] = ‘Cell 4G connection’;
states[Connection.NONE] = ‘No Network connection’;alert( states[networkState]);
}
April 9, 2013 at 3:27 pm #337814
hardsofftMemberany one there to help me with. i was in the final stage of my app…
April 10, 2013 at 6:40 pm #337862
support-michaelKeymasterTo restate you have 2 problems right?
1) alert that does not include program title
2) detecting when the device is online or offline1) alert that does not include program title
Use phoneui.alert() for an alert dialog that does not display the program title. phoneui.alert() is a convenience api that uses the cordova notification api in a native app. When used in a webapp you will see the title because phoneui.alert() uses the std javascript alert() for webapp contexts.2) Yes, your code will run only once because when the app is first loaded. You need to listen for events when the device goes offline/online or is paused/resumed. See this article which provides more discussion and example http://www.digitalnoiz.com/mobile-development/phonegap-network-connection-and-events/
Also always check the cordova/phonegap api you plan to use for quirks/issues on the specific os and devices you plan to use: http://docs.phonegap.com/en/2.2.0/cordova_connection_connection.md.html#Connection
April 11, 2013 at 4:12 am #337874
hardsofftMemberhi wayne every thing is fine but with small misunderstanding.2 points i need to do in my task list, i am trying a lot to sort out but please help me with this
1. i need only my app name to be displayed and not.html. i dont want .html to displayed…(screenshot is attached)
2. i need a display to be displayed(Data not found. Tap to try again) when there is no network and when i click on that it should say the screenshot 1 “you are offline”..(screenshot is attached) AND it should be a loop as long as there is no network. when there is network the app should display as normal…
i’m using the code below:
/** * Notification that the UI is about to transition to a new screen. * Perform custom prescreen-transition logic here. * @param {String} currentScreenId * @param {String} targetScreenId * @returns {boolean} true to continue transtion; false to halt transition */ phoneui.prePageTransition = function(currentScreenId,targetScreenId){ // add custom pre-transition code here // return false to terminate transition return true; } /** * Notification that the UI has transitioned to a new screen. * * @param {String} newScreenId */ phoneui.postPageTransition = function(newScreenId) { } /** * Notification that device orientation has changed. * * @param {String} newOrientation */ phoneui.postOrientationChange = function(newOrientation) { } /** * Called when document is loaded. */ phoneui.documentReadyHandler = function() { document.addEventListener("deviceready", onDeviceReady, false); } function onDeviceReady() { checkConnection(); } function checkConnection() { var networkState = navigator.network.connection.type; var states = {}; states[Connection.UNKNOWN] = 'Unknown connection'; states[Connection.ETHERNET] = 'Ethernet connection'; states[Connection.WIFI] = 'WiFi connection'; states[Connection.CELL_2G] = 'Cell 2G connection'; states[Connection.CELL_3G] = 'Cell 3G connection'; states[Connection.CELL_4G] = 'Cell 4G connection'; states[Connection.NONE] = 'No Network connection'; alert( states[networkState]); } function onDeviceReady() { document.addEventListener("pause", onPause, false); } function onPause() { } function onDeviceReady() { document.addEventListener("resume", onResume, false); } function onResume() { setTimeout(function() { // TODO: do your thing! }, 0); } function onDeviceReady() { document.addEventListener("online", onOnline, false); } function onOnline() { } function onDeviceReady() { document.addEventListener("offline", onOffline, false); } function onOffline() { // Handle the offline event alert("You are offline!"); } var offline = $('#offline'); var online = $('#online'); offline.show(); online.hide(); }please help me with this problem…
Attachments:
You must be logged in to view attached files.April 11, 2013 at 8:11 pm #337911
support-octavioMemberHi hardsofft,
>1. i need only my app name to be displayed and not.html. i dont want .html to displayed…(screenshot is attached)
Note that you can achieve this using the phoneui.alert function as Wayne suggested you. See next image:
See attachment IMG_11042013_200720.png
This only works in a native app. In the Test Center and in webapps phoneui.alert() uses the standard javascript alert() which you can only set the msg, not the title or button label.For your second question, are you seeking to show/hide a button programmatically if yes, use next snippets:
$('#m1-test-button').css('visibility', 'visible'); $('#m1-test-button').css('visibility', 'hidden');Attachments:
You must be logged in to view attached files. -
AuthorPosts
