Platform/Android

[다운로드]

개랭갱깽스타 2020. 6. 2. 14:39
//다운로드 받은 앱을 설치, 이전 실행 앱 종료
    public void downloadUpdate(final String downloadFileUrl, final String fileName,final String localpath) {
        new Thread(new Runnable(){
            public void run(){
                Message msg = Message.obtain();
                msg.what = MESSAGE_DOWNLOAD_STARTING;
                msg.obj = localpath + fileName ;
              
                File apkFile = new File ( localpath + fileName );
                Log.d("downloadUpdate","경로1:"+ localpath + fileName  );
                viewUpdateHandler.sendMessage(msg);
              
                downloadUpdateFile(downloadFileUrl, fileName, localpath);              
              
                //다운로드 받은 패키지를 인스톨한다.
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(apkFile),"application/vnd.android.package-archive");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
              
              /*
               * 안드로이드 프로세스는  단지 finish() 만 호출 하면 죽지 않는다.
               * 만약 프로세스를 강제로 Kill 하기위해서는 화면에 떠있는 Activity를 BackGround로 보내고
               * 강제로 Kill하면 프로세스가  완전히 종료가 된다.
               * 종료 방법에 대한 Source는 아래 부분을 참조 하면 될것 같다.
               */
                moveTaskToBack(true);
                finish();
                android.os.Process.sendSignal(android.os.Process.myPid(), android.os.Process.SIGNAL_KILL);
          }
        }).start();
       }
반응형

'Platform > Android' 카테고리의 다른 글

[Activity] 그놈의 생명주기(LifeCycle)  (0) 2020.06.07
[Receiver]  (0) 2020.06.05
[Zxing]  (0) 2020.06.02
[ListView VS RecyclerView]  (0) 2020.05.19
[Android Studio/Eclipse] keymap-단축키  (0) 2020.05.13