1, the following directly to the demo, specific instructions to see code comments:
public class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {s Uper.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); public void installapk (View v) {String path=environment.getexternalstoragedirectory (). toString (); File File=new file (path, "phone.apk"); Uri uri=uri.fromfile (file);//System.out.println (path); Intent intent=new Intent (); Intent.setaction (Intent.action_view),///Intent.setdata (URI),////settype Specifies the data type, it empties the intent bound data, and therefore will be abnormal,// If you set the type earlier, and then set the data, the setting type is not valid, so call the following API, the following is a description of Settype://this is used to create intents this only specify a Type and not data,//for example to indicate the type of data to return Intent.settype ("APPLICATION/VND. Android.package-archive "); If the data type is not set, eventually the application is installed, but the browser intent.setdataandtype (URI, "Application/vnd.andRoid.package-archive "); StartActivity (Intent); } }
2, the file of the APK data type is found in the Tomcat/conf/web.xml, about the MIME type data type, you can search in the Tomcat/conf/web.xml file to find the relevant data type, MIME type is now recognized, Data type standards, the browser also distinguishes between different media resources by MIME type.
Code to implement the installer, which is to turn on the system installation action