코드로 apk 설치 및 마운트 해제

1687 단어 eclipseandroidWebF#
요 며칠 동안 버전 공중 다운로드 업그레이드를 하기 위해 처음에는 곤란한 문제에 부딪혔다. WEB 서버에 클라이언트 코드 프로그램을 다운로드할 수 있도록 가방 서명을 한 패키지를 설치하고 설치를 업데이트했다. 처음에 본인의 코드는 eclipse에서 직접 run으로 디버깅을 설치했다. (elipse는 기본적으로 그의 서명으로)코드가 실행되면 원격 WEB 서버의 APK 패키지를 정상적으로 다운로드할 수 있고 설치를 실행할 수도 있지만 마지막 알림은 apllication is not install입니다.계속 원인을 찾고 코드에 문제가 생겼다고 생각했는데 백엔드 세그먼트 테스트에서 앞뒤 두 설치 패키지의 서명이 일치하지 않아서 버전 업그레이드와 교체에 성공하지 못했습니다!마지막으로 자신의 코드에 서명 패키지를 만들어서 WEB 서버에 있는 패키지 서명과 일치한 다음 명령행adb install d:/apk/xxx를 사용하십시오.apk 방법으로 설치하면 됩니다!
TEST CODE:
public class TestInstallAPK extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  
 // this.unInstallFile();
  
  
  installFile();
 }

 /**
  * install APK code
  */
 private void installFile(){
  Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   intent.setAction(android.content.Intent.ACTION_VIEW);
//   String type = getMIMEType(f);
//   intent.setDataAndType(Uri.fromFile(f), type);

  intent.setDataAndType(Uri.parse("file://" + "/sdcard/Android_gc.apk"),
    "application/vnd.android.package-archive");
  this.startActivity(intent);
 }
 
 /**
  * uninstall APK code
  */
 private void unInstallFile(){
  
  Uri uri=Uri.parse("package:com.gameclient");
  Intent intent = new Intent(Intent.ACTION_DELETE,uri);
  this.startActivity(intent);
  
 }
 
}

좋은 웹페이지 즐겨찾기