无法使用浏览器组件代号one加载本地网站

问题描述 投票:0回答:0

我正在开发一个代号为one的应用程序。我喜欢经营本地网站。

该网站太大,无法放在源代码 (scr/html) 下。 我尝试了几件事: 1 从 sd 卡获取网页并使用 filechooser 和 wb.setUrl 加载。但是随后没有加载目录。 wb.setUrlHierarchy 在 sd 卡上不起作用。

2 我将网站放在 de apphomepath 的 html 目录下。 我使用了这个stackoverflow问题和答案 我有一个 zip 文件中的网站。我在 src 下创建了一个空文件夹 hmtl。 (src/hmtl) 网站太大,不能放在这个目录下。 我把网站放在一个 zip 文件中。我将 zipfile 解压缩到 hmtl 目录的主路径。文件正确下载到.cn1 目录。但是网页第一次没有加载到模拟器中。我第二次运行该应用程序时,网站已加载。 在设备上网站没有加载,不是在我第一次和第二次打开应用程序时。

如何解决这个问题?有什么线索吗?

public void newsf() {

    //1 check of bestande al zijn gedownlad naar ntml file
    String outdir = FileSystemStorage.getInstance().getAppHomePath();
    String F2 = "/index.html";
    String F4 = "html/index.html";
            File f3 = new File(F4);
      if ( f3.exists()) {
                   
       // 2 laten zien van de website  
        bc = new BrowserComponent();  
           try {
           bc.setURLHierarchy(F2);
          hi.add(BorderLayout.CENTER, bc);
            } catch(IOException err) {
          Dialog.show("Error", err.toString() , "OK", null);   
            }
    }   else {
      
      // 1 download van website uit zip file
      getZiphtml();
   
      
     
      
      }
     
         

}

public void getZiphtml( ) {

    InputStream is;
    FileChooser.showOpenDialog(".zip", new ActionListener() {
             @Override
        public void actionPerformed(ActionEvent e) {
              if (e != null && e.getSource() != null) {
                String file = (String)e.getSource();
                Integer prg= -1;
                FileSystemStorage fs = FileSystemStorage.getInstance();
              try {
                  
                  //1 count files
                    Integer count = 0;
                    InputStream is1  = fs.openInputStream(file);
                    ZipInputStream zipStream1 = new ZipInputStream(is1);
                           ZipEntry entry1;
                         while ((entry1 = zipStream1.getNextEntry()) != null) {
                           count= count+1;  
                         }
                
                  //2 get files
                    InputStream is  = fs.openInputStream(file);
                    ZipInputStream zipStream = new ZipInputStream(is);
                    ZipEntry entry;

                   // create a buffer to improve copy performance later.
                    byte[] buffer = new byte[2048];
                   
                   
                    // set dialog
                                     
                    while ((entry = zipStream.getNextEntry()) != null) {
                         String s = entry.getName();

                         String outdir = FileSystemStorage.getInstance().getAppHomePath();
                         if (outdir.length() > 0) {
                             outdir = outdir  ;
                         }
                         String outpath = outdir   + "html/" +  entry.getName();
                         OutputStream output = null;
                         try {
                             
         
                        File f= new File(outpath);
                        File parent = f.getParentFile();
                        if (!parent.exists()) 
                        {
                            parent.mkdirs();
                        }


                         
                             
                       
                             output = FileSystemStorage.getInstance().openOutputStream(outpath);
                             int len = 0;
                             while ((len = zipStream.read(buffer)) > 0) {
                                 output.write(buffer, 0, len);
                            }
                           Thread.sleep(200);
                         } finally {
                             // we must always close the output file
                             if (output != null) {
                                 output.close();

                             }
                            
                         }

                    }
       Dialog.show("Download Webpage", "Webpage is gedonwload" , "OK", null);   
          bc = new BrowserComponent();  
         String F2 = "/index.html";
           bc.setURLHierarchy(F2);
          hi.add(BorderLayout.CENTER, bc);
           
              
              } catch (Exception ex) {
                    Log.p(ex.getMessage(), 0);
            
              }   
    
              } 
             
        }
     
     });}
codenameone
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.