안드로이드 개발 질문/답변
(글 수 45,052)
기존에 안드로이드 어플리케이션이 있습니다.
새로 개발을 하게 됐구요
업데이트형태가 아니고 intent를 통해서
어플을 삭제하고
새로 개발한 어플을 설치하도록 하려고 하는데요
기존의 어플에 대한 삭제를 요청하고
새로운 apk를 설치하는 어플을 만들수 있을까요??
이렇게 하려면 apk 내부에 어플의 apk를 포함을 해야할 것 같은데요
방법이 있는지 궁금합니다~~
새로 개발을 하게 됐구요
업데이트형태가 아니고 intent를 통해서
어플을 삭제하고
새로 개발한 어플을 설치하도록 하려고 하는데요
기존의 어플에 대한 삭제를 요청하고
새로운 apk를 설치하는 어플을 만들수 있을까요??
이렇게 하려면 apk 내부에 어플의 apk를 포함을 해야할 것 같은데요
방법이 있는지 궁금합니다~~
2010.11.11 11:19:53
일단 신규 어플을 설치하게 하구요..
신규 어플 처음 실행 했을 때 설치되어 있는 패키지들 검사해서, 기존에 어플이 설치되어 있으면 삭제하시겠냐고 물어본다음에
확인 누르면 삭제 진행하도록 처리하면 될 것 같은데요^^ㅋ
안드로이드 개발 서적에 Intent 부분을 보면 이런 부분에 대해서 자세히 설명 되어 있습니다.. 책을 찾아보시거나 Intent 사용법에 대해서 자세히 검색해보세요.
2010.11.11 14:01:23
알고 있는 방법은 아래와 같습니다.
protected String downloadApkFile(String url) {
//
String fileName = null;
URLConnection sourceUrl;
try {
//Connect to URL and gets content
sourceUrl = new URL(url).openConnection();
Object data = sourceUrl.getContent();
//find Filename
fileName = sourceUrl.toString();
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
// create/open file in the 'data/data/<app namespace>/files'
// directory
FileOutputStream fos = openFileOutput(fileName,
Context.MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(
(InputStream) data);
int len1 = 0;
while ((len1 = bis.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
bis.close();
} catch (MalformedURLException e) {
Log.i("ghi", e.getMessage());
} catch (IOException e) {
Log.i("ghi", e.getMessage());
}
return getFileStreamPath(fileName).getAbsolutePath();
}
File apkFile = new File(downloadApkFile("http://new.apk"));
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(installIntent);
// DELETE
Uri packageURI = Uri.parse("package:yourapkfullpackagename");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);



