新增下載檔案
private void downloadapk(){
try {
URL url = new URL("http://www.efimoto.com/nilesh/HelloWorldProject.apk");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "filename.apk");
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
<
安裝APK File
private voidinstallApk ( ) { Intent intent = new Intent( Intent. ACTION_VIEW); Uriuri = Uri. fromFile ( new File( "/sdcard/filename. apk ")); intent. setDataAndType ( uri , "application/vnd . android. package-archive"); startActivity( intent);}
參考網址: 請點我
請先 登入 以發表留言。