当按下电源按钮或主页按钮时,如何在我的webview应用程序中禁用YouTube视频?

时间:2016-07-25 17:28:50

标签: android webview

这是我的mainactivity.java文件 我应该输入什么代码?

public  class  MainActivity  extends ActionBarActivity {

    final String TAG = this.getClass().getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView view = (WebView) this.findViewById(R.id.webView);
        view.getSettings().setJavaScriptEnabled(true);
        view.getSettings().setBuiltInZoomControls( true );
        view.getSettings().setSupportZoom( true );
        view.setWebViewClient(new MyBrowser());
        view.loadUrl("http://roestauto.com");
    }

    private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    boolean twice = false;
    @Override
    public void onBackPressed() {

        Log.d(TAG, "click");

        if (twice == true){
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();
            System.exit(0);
        }
        twice = true;
        Log.d(TAG, "twice: " + twice);


//        super.onBackPressed();
        Toast.makeText(MainActivity.this, "Please press BACK again to exit the ROEST Auto app", Toast.LENGTH_SHORT).show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                twice = false;
                Log.d(TAG, "twice: " + twice);
            }
        },3000);
    }
}

0 个答案:

没有答案