admin管理员组

文章数量:1389412

I am using cordova for my android application. I have lots of pages, and my main or homepage is the index.html. How can I check if it's the first time the user to land to the homepage from opening the app (regardless of how many times he clicked and open the app on different time). I just want to check if it is the first time he access the index.html after he opened the app since he can navigate back to homepage anytime from other pages. I'm using cordova and angularjs

I am using cordova for my android application. I have lots of pages, and my main or homepage is the index.html. How can I check if it's the first time the user to land to the homepage from opening the app (regardless of how many times he clicked and open the app on different time). I just want to check if it is the first time he access the index.html after he opened the app since he can navigate back to homepage anytime from other pages. I'm using cordova and angularjs

Share Improve this question edited Feb 2, 2015 at 17:43 user3569641 asked Feb 2, 2015 at 17:37 user3569641user3569641 9221 gold badge19 silver badges51 bronze badges 2
  • Well you can save his IMEI number and pare at the load event. If in your DB the IMEI doesn't exist then its the first time. – MDMalik Commented Feb 2, 2015 at 18:35
  • 1 put a flag in index.html. store that flag to locastorage when he access your index.htm, next time check if that flag exist or not. if it exist then it's not the first time he access index.html else it's the first time. btw index.html is the start page for cordova. so whenever an app starts it will definetly gonna load. PS: localStore is not that persistent as pared to sqlite etc.. – locknies Commented Feb 2, 2015 at 18:52
Add a ment  | 

1 Answer 1

Reset to default 8

In the deviceready event you can make use of localStorage like this.

if(window.localStorage.getItem("loggedIn") != 1) {
// Running for the first time.
window.localStorage.setItem("loggedIn", 1);
console.log("1st time");
}
else
{
//Already run this app before.
console.log("running this for more than one time");
}

or use sqlite and store your values like this in a db and check it everytime you opens up the app.

sessionStorage Will be cleared each time you exit the app,

var keyName = window.sessionStorage.key(0); //Get key name
window.sessionStorage.setItem("key", "value"); //Set item
var value = window.sessionStorage.getItem("key");// Get item
window.sessionStorage.removeItem("key"); //Remove Item 
window.sessionStorage.clear();//Clear storage

本文标签: javascriptHow to check android app first runCordovaStack Overflow