Simply determine if the phone app was installed for the first time

Source: Internet
Author: User

The method is written in the app to enter the page activity in order to call the following Getfilesdir () method:

Protected Boolean Firstsinstall () {

File files = Getfilesdir ();/**The Getfilesdir () method is used to get the/data/data//files directory*/
File Installfile = new file (files, "Install");/** new Install file */
int NEWVC = 0;
try {
NewVersion = Getpackagemanager (). Getpackageinfo (Getpackagename (), 0). versioncode;/** Get app Current version number NewVersion */
}
catch (Exception e) {
}

Boolean firstinstall = Installfile.exists ();
if (!firstinstall) {/** folder does not exist, it indicates initial installation */
Installfile.mkdirs ();
try {
New file (Installfile, NewVersion + ""). CreateNewFile ();//Create a new document with a version number
}
catch (Exception e) {
E.printstacktrace ();
}
return true;
}
else {
string[] fs = Installfile.list ();
if (fs = = NULL | | fs.length = = 0) {/** Previous version is empty, indicating that the application may have been killed, also equivalent to the initial installation */
try {
New File (Installfile, NewVersion + ""). CreateNewFile ();
}
catch (Exception e) {
E.printstacktrace ();
}
return true;
}
String Lastv = fs[0];
if (Newvc > Integer.parseint (LASTV)) {/** If the current version number is greater than the previous version number */
try {
New File (Installfile, NewVersion + ""). CreateNewFile ();
for (String Vf:fs) {
File temp = new file (Installfile, VF);
if (temp.exists ()) Temp.delete ();/** Delete file */
}
return true;
}
catch (Exception e) {
E.printstacktrace ();
}
}
}
return false;
}

Simply determine if the phone app was installed for the first time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.