getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
AlertDialog. builder builder = Builder (builder. setTitle ("upgrade prompt" builder. setMessage ("" builder. setPositiveButton ("Upgrade", onClick (DialogInterface dialog, builder. setNegativeButton ("cancel", onClick (DialogInterface dialog ,}
String serverurl = getResources (). getString (R. string. serverurl): Obtain the URL address for accessing the server configuration information (that is, the info. xml file of the server.
The URL address contains the config in the values folder. the purpose of the xml file is that when the URL needs to be changed, you do not need to modify it in the code. You only need to modify the configuration file to reduce development costs. The configuration information is as follows:
<?xml version="1.0" encoding="utf-8"?><resources> <string name="serverurl">http:<resources>
UpdateInfo getUpdateInfo(InputStream is) XmlPullParser parser= parser.setInput(is,"utf-8" UpdateInfo info= type= (type!= (type==XmlPullParser.START_TAG){ ("version" String version= } ("description" String description= } ("apkurl" String apkurl= type= }
Because the networking process is generally a time-consuming operation, to avoid ANR exceptions, we open a subthread in the main thread to check the version number online. In this case, we should also configure the network permission information in the list file:
<uses-permission android:name="android.permission.INTERNET"/>
URL url= File file= FileOutputStream fos= HttpURLConnection conn= conn.setRequestMethod("GET" conn.setConnectTimeout(5000 max= InputStream is= [] buf= [1024 len=0 process=0 ((len=is.read(buf))!=-1 fos.write(buf, 0 process+= Thread.sleep(30 } }
urlpath.substring(urlpath.lastIndexOf("/")+1 }
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Intent intent= intent.setAction("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT" intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent);