应用程序未安装

时间:2011-09-12 05:00:31

标签: android

下载文件已经成功,但安装时出现错误“应用程序未安装” 我已经使用了INSTALL_NON_MARKET_APPS权限 安装提示已存在,但每次我尝试,它总是“应用程序未安装”错误。

public void Update(String apkurl){
    try {
          URL url = new URL(apkurl); 
          HttpURLConnection c = (HttpURLConnection) url.openConnection();
          c.setRequestMethod("GET");
          c.setDoOutput(true);
          try{
          c.connect();
          } catch (Exception e) {
              Toast.makeText(getApplicationContext(),e.getMessage() , Toast.LENGTH_LONG).show();
          }
          String PATH = Environment.getExternalStorageDirectory() + "/download/";
          File file = new File(PATH);
          file.mkdirs();
          File outputFile = new File(file, "prov1.apk");
          FileOutputStream fos = new FileOutputStream(outputFile);

          InputStream is = c.getInputStream();

          byte[] buffer = new byte[1024];
          int len1 = 0; 
          while ((len1 = is.read(buffer)) != -1) {
              fos.write(buffer, 0, len1);
          } 
          fos.close();
          is.close();//till here, it works fine - .apk is download to my sdcard in download file

          Intent intent = new Intent(Intent.ACTION_VIEW);  
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

          intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "prov1.apk")), "application/vnd.android.package-archive");

          startActivity(intent);   

      } catch (IOException e) {
          Toast.makeText(getApplicationContext(), "Update error!", Toast.LENGTH_LONG).show();
      }
}  

我已经阅读了关于这个主题的另一个问题,但仍然卡住了。我非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您可能已经拥有一些具有相同包名称的应用程序的问题之一。 例如,如果您尝试将com.something.prov1安装在可能已存在的相同软件包中。如果是这种情况,请先卸载应用程序

adb uninstall com.something.prov1
相关问题