AndroidProgramUseCode!!!
Installation:
String STR = "/canavacancel.apk "; String filename = environment. getexternalstoragedirectory () + STR; Intent intent = new intent (intent. action_view ); I Ntent. setdataandtype (URI. fromfile (new file (filename), "application/vnd. Android. Package-Archive "); Startactivity (intent );
Uninstall: Uri packageuri = URI. parse ("package: COM. Demo. canavacancel"); intent uninstallintent = new intent (intent. action_delete, packageuri); startactivity (uninstallintent ); Environmen T has some methods to get environment variables. Package: COM. Demo. canavacancel. This form is package: the complete program path (package name + program name ).
// Download the APK program code
Protected file downloadfile (string httpurl ){
// Todo auto-generated method stub
Final string filename = "updata.apk ";
File tmpfile = new file ("/sdcard/update ");
If (! Tmpfile. exists ()){
Tmpfile. mkdir ();
}
Final file = new file ("/sdcard/update/" + filename );
Try {
URL url = new URL (httpurl );
Try {
Httpurlconnection conn = (httpurlconnection) URL
. Openconnection ();
Inputstream is = conn. getinputstream ();
Fileoutputstream Fos = new fileoutputstream (File );
Byte [] Buf = new byte [1, 256];
Conn. Connect ();
Double COUNT = 0;
If (conn. getresponsecode () & gt; = 400 ){
Toast. maketext (main. This, "connection timeout", Toast. length_short)
. Show ();
} Else {
While (count <= 100 ){
If (is! = NULL ){
Int numread = is. Read (BUF );
If (numread <= 0 ){
Break;
} Else {
FOS. Write (BUF, 0, numread );
}
} Else {
Break;
}
}
}
Conn. disconnect ();
FOS. close ();
is. close ();
}catch (ioexception e) {
// todo auto-generated Catch Block
E. printstacktrace ();
}
} Catch (malformedurlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Return file;
}
// Open the APK program code
Private void openfile (File file ){
// Todo auto-generated method stub
Log. E ("openfile", file. getname ());
Intent intent = new intent ();
Intent. addflags (intent. flag_activity_new_task );
Intent. setaction (Android. content. Intent. action_view );
Intent. setdataandtype (URI. fromfile (file ),
"Application/vnd. Android. Package-Archive ");
Startactivity (intent );
}