如何在报纸Webview Android Eclipse上显示横幅广告

时间:2015-11-22 05:42:11

标签: java android webview

如何在报纸链接上显示横幅广告" Webview" Android Eclipse 我已经设置了Admob"横幅广告和非页内广告"在我的项目上。非页内广告正常工作,但横幅广告未在Webview上展示。
这里是我的Java& xml代码

Details_Newspaper.Java



package com.nasir.newspaper;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewConfiguration;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;

@SuppressLint("SetJavaScriptEnabled")
public class Details_Newapaper extends Activity {

	WebView mWebview;
	
	AdView mAdView;
	private InterstitialAd interAd;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Adds Progrss bar Support
		this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.details_newapaper );
		
		// For Banner Ads View
        AdView mAdView = (AdView) findViewById(R.id.adView);
		AdRequest adRequest = new AdRequest.Builder().build();
		mAdView.loadAd(adRequest);
		
		// For Interstitial Ads View
		interAd = new InterstitialAd(this);
		interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
		
		AdRequest adRequest_FC = new AdRequest.Builder().build();
		interAd.loadAd(adRequest_FC);
		interAd.setAdListener(new AdListener() {
			
			@Override
			public void onAdLoaded() {
				// TODO Auto-generated method stub
				displayInterstitial();
			}
		});
		
		getOverflowMenu();
				
		// Makes Progress bar Visible
		getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 
				
		mWebview = new WebView(this);

		mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
		mWebview.getSettings().setSupportZoom(true);		//Zoom Control on web (You don't need this 
		 													//if ROM supports Multi-Touch		
		mWebview.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
		
		
		final Activity Activity = this;
		
		mWebview.setWebChromeClient(new WebChromeClient() {
	        public void onProgressChanged(WebView view, int progress)   
	        {
	        	//Make the bar disappear after URL is loaded, and changes string to Loading...
	        	Activity.setTitle("Loading..... Please Wait");
	        	Activity.setProgress(progress * 100); //Make the bar disappear after URL is loaded
	        	
	        	// Return the app name after finish loading
	            if(progress == 100)
	            	Activity.setTitle(R.string.app_name);
	          }
	        });

		mWebview.setWebViewClient(new WebViewClient() {
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Toast.makeText(Activity, description, Toast.LENGTH_SHORT).show();
			}
		});

		String customHtml = getIntent().getStringExtra("Newspaper_Name");
		mWebview.loadUrl(customHtml);
		setContentView(mWebview);
		mWebview.getSettings().setBuiltInZoomControls(true);

	}
	
	
//  On Back Button Press, Go to Website Back
	@Override
	public void onBackPressed() {
		if (mWebview.isFocused() && mWebview.canGoBack()) {
			mWebview.goBack();
		} else {
			super.onBackPressed();
			finish();
		}
	}
	
	
	
	
	
	// For Interstitial Ads View	
	public void displayInterstitial() {
		
		if (interAd.isLoaded()) {
			interAd.show();
			
		}
	}

    /** Called when leaving the activity */
    @Override
    public void onPause() {
        if (mAdView != null) {
            mAdView.pause();
        }
        super.onPause();
    }

    /** Called when returning to the activity */
    @Override
    public void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

    /** Called before the activity is destroyed */
    @Override
    public void onDestroy() {
        if (mAdView != null) {
            mAdView.destroy();
        }
        super.onDestroy();
    }
    
    
    
    
    
    
	
	// inflate for action bar
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.refresh_main, menu);
        return true;
    }
 
    // handle click events for action bar items
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
 
        switch (item.getItemId()) {
 
            case R.id.refresh:
                showToast("Refresh was clicked.");
                return true;
 
            
 
//            case R.id.share:
//                showToast("Share was clicked.");
//                return true;
// 
            default:
                return super.onOptionsItemSelected(item);
        }
    }
 
    // put the other two menu on the three dots (overflow)
    private void getOverflowMenu() {
 
        try {
 
           ViewConfiguration config = ViewConfiguration.get(this);
           java.lang.reflect.Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
           if(menuKeyField != null) {
               menuKeyField.setAccessible(true);
               menuKeyField.setBoolean(config, false);
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
 
     }
 
    // so that we know something was triggered
    public void showToast(String msg){
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
 
}




details_newspaper.xml



<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top|fill_vertical"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/webView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
       
    </LinearLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-1528948212400372/9325301249" >
    </com.google.android.gms.ads.AdView>

</RelativeLayout>
&#13;
&#13;
&#13;

0 个答案:

没有答案