2014-12-04 103 views
1

我正在開發內部服務器的自動更新。
下載的效果很好,但是當我試圖安裝下載的apk時,我得到:「parse error,problem parsing package」。android解析錯誤解析包

private BroadcastReceiver mDownloadReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { 
      long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); 
      Log.i(VERSION_LOG_TAG, "received download id: " + downloadId); 

      DownloadManager.Query query = new DownloadManager.Query(); 
      query.setFilterById(enqueue); 
      Cursor cursor = dm.query(query); 
      if (cursor.moveToFirst()) { 
       int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); 

       if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(columnIndex)) { 
        String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); 
        Log.i(VERSION_LOG_TAG, uriString); 

        Intent installIntent = new Intent(Intent.ACTION_VIEW); 
        File apk = new File(Uri.parse(uriString).getPath()); 
        installIntent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive"); 
        startActivity(installIntent); 
       }else{ 
        Log.e(VERSION_LOG_TAG, "download failed"); 
       } 
      } 
     } 
    } 
}; 

我認爲這是因爲網址:content://downloads/my_downloads/13 我該怎麼辦錯了嗎?

+1

該問題的解決方案在下面[question] [1] [1]:http://stackoverflow.com/questions/27404478/android-cant-open-file – NickF 2014-12-23 21:42:11

回答

0

只是嘗試從文件管理器應用程序中打開下載的文件,或者您也可以下載前文件瀏覽器,因爲它不直接從應用程序中訪問文件的URL,那麼它不會給解析錯誤