2017-05-30 151 views
0

我想在我的webview android應用上顯示插頁式廣告,但我無法實現它。如何在webView應用程序中顯示插頁式廣告?

  • 我有一個完全在線的webview應用程序,沒有脫機頁面或任何按鈕或菜單。

  • 我不想在啓動或關閉應用程序時顯示插頁式廣告。

  • 當用戶使用該webview應用瀏覽我的網站時應顯示廣告。
  • 我認爲在x分鐘後使用插頁式廣告,但是我在x分鐘後學習插頁式廣告不是herehere的好主意。
  • 那麼如何告訴我如何在我的應用上顯示插頁式廣告?我沒有任何按鈕或菜單,但只有一個網站可供瀏覽。
  • 請教我如何在我的webview應用程序中使用插頁式廣告。
  • 我試過併成功實施了BANNER廣告。 (但代碼如下)但無法通過任何方式實施插頁式廣告
  • 我在這個領域非常新,所以請建議我詳細說明處理方式,其中放置代碼等

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.xxxx.yyyyy.MainActivity" 
    android:layout_gravity="center" 
    android:id="@+id/fl"> 

    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/wv"/> 
    <ProgressBar 
     android:id="@+id/progressBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 


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

使用火力Mainactivity的java

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; 
import com.google.android.gms.ads.MobileAds; 

MobileAds.initialize(this, "xxxxxx~xxxxxx"); 
     AdView adView = (AdView)findViewById(R.id.adView); 

     AdRequest adRequest = new AdRequest.Builder() 
       .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
       .addTestDevice("xxxxxxx") 
       .build(); 
     adView.loadAd(adRequest); 

(build.gr adle)

compile 'com.google.firebase:firebase-ads:10.2.6' 
+0

我不要認爲插頁式廣告會爲您提供自定義點擊處理機制。但是,如果您想處理用戶點擊,則應查看NativeCustomTemplateAds https://developers.google.com/mobile-ads-sdk/docs/dfp/android/native – Ezio

回答

0

最好的可供您的選擇是一個web視圖客戶端設置爲網頁視圖,並載入廣告時,用戶通過使用shouldOverrideUrlLoading方法

mWebView.setWebViewClient(new WebViewClient() { 

    @Override 
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString)  { 

//urlNewString is url for loading Ad then load Ad 

return false; 
} 

@Override 
public void onPageStarted(WebView view, String url) { 

    } 

}); 
0

是的,你可以顯示間質性打開一些特定的URL在Android WebView中使用JavascriptInterface單擊按鈕時從您的Web應用程序中啓動。

  1. 首先添加addJavascriptInterface到你的webview。
  2. 爲JavascriptInterface
  3. 創建顯示廣告說「showAd()」內,你Acitvity
  4. 在javascriptInterface類中創建一個methos並致電showAd()來顯示廣告的方法創建一個CALSS。

對於參考文獻參見上的活動此How to call admob Interstitial ad from android webview JavascriptInterface

0

烏爾表示網頁視圖使用Android生命週期:-)。當最小化烏爾應用的intertitial廣告將加載和應用程序時,將打開的廣告將shows.below是一個例子即時通訊做這樣我的應用程序的顯示廣告....希望這有助於

@Override 
protected void onDestroy() { 
    super.onDestroy(); 


} 

@Override 
protected void onStop() { 
    super.onStop(); 
    loadads(); 

} 

@Override 
protected void onResume() { 
    super.onResume(); 
    showads(); 
} 

@Override 
protected void onPause() { 
    super.onPause(); 

} 
相關問題