显示非页面onclick或打开网址

时间:2015-03-10 08:35:50

标签: java javascript android webview

我想显示插页式onclick或打开网址.. 在webview中 请帮助我

我的ShowWebViev.java:

public class ShowWebView extends Activity {

    //private Button button;
    private WebView webView;
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_web_view);

        AdView mAdView = (AdView) findViewById(R.id.adView );
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);


        //Get webview
        webView = (WebView) findViewById(R.id.webView1);
        startWebView("http://MYsite");

    }
    public class ShowWebView extends Activity {

        private InterstitialAd interstitial;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.show_web_view);

            // Create the interstitial.
            interstitial = new InterstitialAd(this);
            interstitial.setAdUnitId("ca-app-pub-555555555555555/12334567890");

            // Create ad request.
            AdRequest adRequest = new AdRequest.Builder().build();

            // Begin loading your interstitial.
            interstitial.loadAd(adRequest);

        }

        // Invoke displayInterstitial() when you are ready to display an interstitial.
        public void displayInterstitial() {
            if (interstitial.isLoaded()) {
                interstitial.show();
            }
        }
    }

    private void startWebView(String url) {

        //Create new webview Client to show progress dialog
        //When opening a url or click on link

        webView.setWebViewClient(new WebViewClient() {
            ProgressDialog progressDialog;

            //If you will not use this method url links are opeen in new brower not in webview
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("rtmp:") | url.endsWith(".m3u8") | url.startsWith("http://212.35.75.130")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setComponent(new ComponentName("com.xmtvplayer.watch.live.streams", "org.zeipel.videoplayer.XMTVPlayer"));
                    intent.setData(Uri.parse(url));
                    intent.putExtra("secure_uri", true);


                    startActivity(intent);

                    return true;
                } else{
                    Toast.makeText(getApplicationContext(), "tv", Toast.LENGTH_SHORT).show();                }

                    return false;

            }




            /*/Show loader on url load
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                    // in standard case YourActivity.this
                    progressDialog = new ProgressDialog(ShowWebView.this);
                    progressDialog.setMessage("Loading... plz download XMTV Player To Watch Channel");
                    progressDialog.show();
                }
           }*/
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                startWebView("file:///android_asset/myerrorpage.html");


        }
            public void onPageFinished(WebView view, String url) {
                try{
                    if (progressDialog.isShowing()) {
                        progressDialog.dismiss();
                        progressDialog = null;
                    }
                }catch(Exception exception){
                    exception.printStackTrace();
                }
            }

        });




        // Javascript inabled on webview
        webView.getSettings().setJavaScriptEnabled(true);

        // Other webview options
        /*
        webView.getSettings().setUseWideViewPort(true);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setScrollbarFadingEnabled(false);
        webView.getSettings().setBuiltInZoomControls(true);
        */


/*
         String summary = "<html><body>You scored <b>192</b> points.</body></html>";
         webView.loadData(summary, "text/html", null);
*/
        //Load url in webview
        webView.loadUrl(url);

        webView.clearHistory();

    }
    @Override
    public boolean onCreateOptionsMenu (Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == R.id.ref){
            webView.reload();
            return true;

        }
        return super.onOptionsItemSelected(item);

    }

1 个答案:

答案 0 :(得分:0)

关于xmtv播放器的文档,您可以使用startActivityForResult代替startActivity。您可以在活动onActivityResult上调用非页内广告。

public void XMTVPlayerPlayUri(String Title,String uri){
    // [String]  adszone -  get zone id after filling form. 
    // [Integer] adstime -  how long ad will stay before user will able to close it, value is in seconds.



    Bundle bnd = new Bundle();
    bnd.putString("path", uri);
    bnd.putString("name", Title);
    bnd.putString("adszone", "15E56089-CB15-4AA7-8D1B-574E899DE009"); // change adszone with your own id.
    bnd.putInt("adstime",30);
    Intent intent = new Intent();
    intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
    intent.putExtras(bnd);
    startActivityForResult(intent, 100);
}