Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check android app first run - Cordova

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

like image 503
user3569641 Avatar asked Feb 11 '23 00:02

user3569641


1 Answers

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
like image 70
locknies Avatar answered Feb 13 '23 14:02

locknies