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