0

我已經實現了Android白日夢服務,其中我從斷言中播放視頻, 我已經把按鈕放在那裏,onclick監聽器我想打開帶有鏈接的webview ,每一個事情發展順利,但是我不能夠處理的WebView,當我點擊這個消息出現andorid白日夢服務webview(上下文需要flag_activity_new_task標誌)

Unfortunatley應用程序已經停止

按鈕,出現在日誌中的錯誤消息是

AndroidRuntime(827):致命例外: android.util.AndroidRuntimeException:從活動con文本外部調用startActivity()需要FLAG_ACTIVITY_NEW_TASK標誌。這真的是你想要的嗎?

我創建的XML文件中的WebView

我調用web視圖代碼:

final WebView webView = (WebView)this.findViewById(R.id.webView1); 

    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on click 
      vv.stopPlayback(); 
      vv.setVisibility(View.GONE);//for media player 

      webView.setVisibility(View.VISIBLE); 
      webView.loadUrl("http://www.google.com"); 
     } 
    }); 

回答

0

很多搜​​索我在這裏找到我的問題的答案之後是鏈接幫助我最

link

基本上我只是把這個在我的Android dreamservice類代碼

private class LinkLauncher extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 
     finish(); 
     return true; 
    } 

,並使用web視圖如下

  WebView webview = (WebView) findViewById(R.id.webView1); 
      webview.setVisibility(View.VISIBLE); 
      webview.setWebViewClient(new LinkLauncher()); 

      WebSettings webSettings = webview.getSettings(); 
      webSettings.setJavaScriptEnabled(true); 

      webview.loadUrl("http://www.google.com"); 

我寫的答案,可以幫助其他人。 謝謝

+0

你甚至不需要實現自定義WebViewClient。 只需在WebView上設置一個空的WebViewClient就可以解決問題(是的,這是令人驚訝的:))。 – Lizozom

相關問題