2012-09-20 41 views
0

我是非常新的android如此裸露與我。所以在我的onCreate方法中,我創建一個webView,然後加載保存在我的資產文件夾中的HTML文件。這一切工作正常。當一個按鈕被按下時,它使用javascript發送一個呼叫到這個方法來打開qr碼掃描器。zbar掃描儀集成到Android應用程序

webView.setWebViewClient(new WebViewClient()   
    { 
     /* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link, 
     * but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */ 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) 
     {    
      System.out.println(url);     

      if (url.equals("fake://qr_scan")) 
      { 
       launchQRScanner(view); 
      } 
      return false; 
     } 
    }); 

這裏是法launchQRScanner()

public void launchQRScanner(View v) { 
    if (isCameraAvailable()) { 
     Intent intent = new Intent(this, ZBarScannerActivity.class); 
     intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE}); 
     startActivityForResult(intent, ZBAR_SCANNER_REQUEST); 

    } else { 
     Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show(); 
    } 
} 

所以這個作品首次按下按鈕。 qr代碼閱讀器以意圖打開,它會掃描,消失並正確返回值。但是在每次按下按鈕之後,方法shouldOverrideUrlLoading()都不會被調用。可能與離開應用程序並回來有關嗎?似乎無法弄清楚。 謝謝你的幫助!

BTW這是我用來實現QR碼閱讀器 https://github.com/DushyanthMaguluru/ZBarScanner

回答

0

固定的,只是有條形碼掃描後重新加載web視圖項目。簡單的修復。