0
나는 android 응용 프로그램에서 무선 업데이트를 포함 할 수있는 android 응용 프로그램을 생성 중입니다. 그래서 내가 아래에 코드를 사용하여 서버에서 설치하는 업데이트가 트리거됩니다 적은 경우 설치된 응용 프로그램의 버전 코드를 비교할 수 있도록 버전 코드를 얻기위한 Webservice 생성하고 있습니다. 내가 무엇입니까 젤리 빈에서 그것을 시도 versions.If젤리 빈에 "의도를 사용하여 apk 설치"오류가 발생했습니다.
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "yourapp.apk");
downloadFile(file_url, outputFile);
installApk();
//downloadfile function
private static void downloadFile(String url, File outputFile) {
try {
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
fos.write(buffer);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException",e+"");
return;
} catch (IOException e) {
Log.e("IOException",e+"");
return;
}
}
//install apk file function
private void installApk(){
Intent installer = new Intent();
installer.setAction(android.content.Intent.ACTION_VIEW);
installer.putExtra(Intent.ACTION_PACKAGE_REPLACED, "org.wannatrak.android");
installer.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "yourapp.apk")), "application/vnd.android.package-archive");
installer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(installer);
}
I am generating an android application which capable to include over-the-air updation in the android application. So that I am generating a Webservice for getting the versioncode so that I will compare the versioncode of installed application if it is lesser then I will trigger there is an update to install from the server, for this I using below code.
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "yourapp.apk");
downloadFile(file_url, outputFile);
installApk();
//downloadfile function
private static void downloadFile(String url, File outputFile) {
try {
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
fos.write(buffer);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException",e+"");
return;
} catch (IOException e) {
Log.e("IOException",e+"");
return;
}
}
//install apk file function
private void installApk(){
Intent installer = new Intent();
installer.setAction(android.content.Intent.ACTION_VIEW);
installer.putExtra(Intent.ACTION_PACKAGE_REPLACED, "org.wannatrak.android");
installer.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "yourapp.apk")), "application/vnd.android.package-archive");
installer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(installer);
}
위의 작품뿐만 개까지 4.0 "패키지 오류 구문 분석 오류가 있습니다"날이
감사를 문제 해결하는 데 도움이 바랍니다.