2017-02-16 45 views
1
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 


    public void onClick(View v) { 
     mScannerView = new ZXingScannerView(this); 
     setContentView(mScannerView); 
     mScannerView.setResultHandler(this); 
     mScannerView.startCamera(); 

    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     mScannerView.stopCamera(); 
    } 

    @Override 
    public void handleResult(final Result result) { 
     //Do anything with result here :D 
     Log.w("handleResult", result.getText()); 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Scan result"); 
     builder.setMessage(result.getText()); 
     AlertDialog alertDialog = builder.create(); 
     alertDialog.show(); 


     Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText().toString())); 
     startActivity(browserIntent); 

      mScannerView.resumeCameraPreview(this); 
    } 

} 

我想在掃描完成後直接打開URL,然後重新打開相機。誰能幫幫我嗎 ?如何在不打開網頁瀏覽器的情況下請求打開網址?

+0

嘗試和創建你自己的活動來處理請求在您的WebView中打開URL。 – MKJParekh

+1

「直接打開網址」是什麼意思?你想展示網站,還是想獲取一些數據? – Malik

+0

「open」是什麼意思?您是否試圖將URL的內容直觀地呈現給您的應用的用戶?或者你是否試圖從這個網址下載數據以便在你的應用中使用? –

回答

0

嘗試創建自己的活動來處理打開URL的請求。

當我開始學習android及其意圖時,我發現它很混亂。但清單中的類別BROWSABLE執行以下操作。

瀏覽器可以安全地調用目標活動以顯示鏈接引用的數據 - 例如圖像或電子郵件。

瞭解更多關於:http://developer.android.com/guide/components/intents-filters.html

兩個其他答案打開標準網頁瀏覽器,並轉到指定的地址。如果你想定製的瀏覽器進行第二活動像這樣的例子Web視圖:

http://www.mkyong.com/android/android-webview-example/

0

使用的WebView加載網址,如下所示:

webView= (WebView) findViewById(R.id.webview); 
    webView.setWebChromeClient(new WebChromeClient()); 
    webView.setWebViewClient(new WebViewClient()); 
相關問題