Because the application installation and uninstall module has been written on the Android system, so we just need to activate it.
Attention:
Intent.setdataandtype (uri.fromfile (file), "Application/vnd.android.package-archive"); In this sentence, the first parameter is the path to the APK to install. The second parameter is the type corresponding to the APK. Can be found in the Web.xml in the Conf directory under the installation directory of Tomcat.
Program Run screenshot:
The code implementation is as follows:
1, Main.xml
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" match_parent "
android:layout_height=" match_parent "
android:o" rientation= "vertical" >
<button
android:layout_width= "Wrap_content"
Wrap_content "
android:text=" Installation "
android:onclick=" Install "
/>
<button
android: Layout_width= "Wrap_content"
android:layout_height= "wrap_content"
android:text= "Uninstall"
Android:o nclick= "Uninstall"
/>
</LinearLayout>
2, Mainactivity
package Com.njupt.install;
Import Java.io.File;
Import Android.net.Uri;
Import Android.os.Bundle;
Import android.os.Environment;
Import android.app.Activity;
Import android.content.Intent;
Import Android.view.Menu;
Import Android.view.View; public class Mainactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.onc
Reate (savedinstancestate);
Setcontentview (R.layout.main);
public void Install (View v) {Intent Intent = new Intent ();
Intent.setaction (Intent.action_view);
File File = new file (Environment.getexternalstoragedirectory (), "htmlui1.apk");
Intent.setdataandtype (uri.fromfile (file), "application/vnd.android.package-archive");
StartActivity (Intent);
public void Uninstall (View v) {Intent Intent = new Intent ();
Intent.setaction (Intent.action_delete);
Intent.setdata (Uri.parse ("Package:com.njupt.htmlui1"));
StartActivity (Intent); @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds the items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true; }
}