我在Android應用程序中使用Webview。當我運行該應用程序時,admob不在第一次運行中顯示。如果我再次運行該應用程序,admob顯示。這是爲什麼發生? 我該怎麼做代碼?無法加載廣告:0 - admob未顯示在應用程序中
我看到在我的日誌異常(下面的代碼):
public class WebViewClientDemoActivity extends Activity {
WebView web;
ProgressDialog pd;
Button button1;
private AdView adView;
private InterstitialAd interstitial;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
interstitial = new InterstitialAd(WebViewClientDemoActivity.this);
interstitial.setAdUnitId("ca-app-pub-9902624673333052/2524062321");
AdRequest adRequest2 = new AdRequest.Builder()
.build();
adView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
interstitial.loadAd(adRequest2);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
web.loadUrl("http://hostwr.com/app1/ibr/");
interstitial.show();
}
});
if(isNetworkStatusAvialable (getApplicationContext())) {
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://hostwr.com/app1/ibr/");
} else {
Toast.makeText(getApplicationContext(), "لا يوجد اتصال بالانترنت !!!",Toast.LENGTH_LONG).show();
}
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (pd == null) {
// in standard case YourActivity.this
pd = new ProgressDialog(WebViewClientDemoActivity.this);
pd.setMessage("انتظر لحظة...");
pd.setCanceledOnTouchOutside(false);
pd.show();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
try{
if (pd.isShowing()) {
pd.dismiss();
pd = null;
}
}catch(Exception exception){
exception.printStackTrace();
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(web.canGoBack()){
web.goBack();
}else{
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
public void onPause() {
adView.pause();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
adView.resume();
}
@Override
public void onDestroy() {
adView.destroy();
super.onDestroy();
}
public static boolean isNetworkStatusAvialable (Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null)
{
NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
if(netInfos != null)
if(netInfos.isConnected())
return true;
}
return false;
}
}
登錄貓
10-27 19:37:01.806: V/WebViewChromiumFactoryProvider(1188): Binding Chromium to main looper Looper (main, tid 1) {5284e270}
10-27 19:37:01.806: I/LibraryLoader(1188): Expected native library version number "",actual native library version number ""
10-27 19:37:01.806: I/chromium(1188): [INFO:library_loader_hooks.cc(116)] Chromium logging enabled: level = 0, default verbosity = 0
10-27 19:37:01.870: I/BrowserStartupController(1188): Initializing chromium process, renderers=0
10-27 19:37:02.142: E/AudioManagerAndroid(1188): BLUETOOTH permission is missing!
10-27 19:37:02.566: D/libEGL(1188): loaded /system/lib/egl/libEGL_genymotion.so
10-27 19:37:02.566: D/(1188): HostConnection::get() New Host Connection established 0xb79670d0, tid 1188
10-27 19:37:02.574: D/libEGL(1188): loaded /system/lib/egl/libGLESv1_CM_genymotion.so
10-27 19:37:02.574: D/libEGL(1188): loaded /system/lib/egl/libGLESv2_genymotion.so
10-27 19:37:02.666: W/chromium(1188): [WARNING:mailbox_synchronizer.cc(36)] MailboxSync not supported due to missing EGL image/fence support
10-27 19:37:02.778: D/dalvikvm(1188): GC_FOR_ALLOC freed 91K, 4% free 3805K/3960K, paused 2ms, total 2ms
10-27 19:37:02.782: I/dalvikvm-heap(1188): Grow heap (frag case) to 6.192MB for 2536932-byte allocation
10-27 19:37:02.786: D/dalvikvm(1188): GC_FOR_ALLOC freed <1K, 3% free 6282K/6440K, paused 2ms, total 2ms
10-27 19:37:03.078: W/chromium(1188): [WARNING:proxy_service.cc(890)] PAC support disabled because there is no system implementation
10-27 19:37:03.082: W/GooglePlayServicesUtil(1188): Google Play services is missing.
10-27 19:37:03.130: D/dalvikvm(1188): DexOpt: --- BEGIN 'ads-456905124.jar' (bootstrap=0) ---
10-27 19:37:03.138: W/GooglePlayServicesUtil(1188): Google Play services is missing.
10-27 19:37:03.142: I/Ads(1188): Starting ad request.
10-27 19:37:03.142: I/Ads(1188): Use AdRequest.Builder.addTestDevice("3A1ADC6C8879D79A9A6D537320830C10") to get test ads on this device.
10-27 19:37:03.146: W/GooglePlayServicesUtil(1188): Google Play services is missing.
10-27 19:37:03.146: I/Ads(1188): Starting ad request.
10-27 19:37:03.146: I/Ads(1188): Use AdRequest.Builder.addTestDevice("3A1ADC6C8879D79A9A6D537320830C10") to get test ads on this device.
10-27 19:37:03.250: D/dalvikvm(1188): DexOpt: --- END 'ads-456905124.jar' (success) ---
10-27 19:37:03.250: D/dalvikvm(1188): DEX prep '/data/data/com.hostwr.ibrahemfeqy/cache/ads-456905124.jar': unzip in 0ms, rewrite 117ms
10-27 19:37:03.498: W/EGL_genymotion(1188): eglSurfaceAttrib not implemented
10-27 19:37:03.502: E/OpenGLRenderer(1188): Getting MAX_TEXTURE_SIZE from GradienCache
10-27 19:37:03.502: E/OpenGLRenderer(1188): MAX_TEXTURE_SIZE: 8192
10-27 19:37:03.506: E/OpenGLRenderer(1188): Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
10-27 19:37:03.510: E/OpenGLRenderer(1188): MAX_TEXTURE_SIZE: 8192
10-27 19:37:03.510: D/OpenGLRenderer(1188): Enabling debug mode 0
10-27 19:37:03.514: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:03.702: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.582: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.622: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.638: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.658: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.678: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.710: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.734: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.758: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.782: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.802: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.822: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.842: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:04.862: W/AwContents(1188): nativeOnDraw failed; clearing to background color.
10-27 19:37:06.706: D/dalvikvm(1188): GC_FOR_ALLOC freed 467K, 8% free 6639K/7168K, paused 4ms, total 4ms
10-27 19:37:06.706: I/dalvikvm-heap(1188): Grow heap (frag case) to 7.141MB for 629772-byte allocation
10-27 19:37:06.718: D/dalvikvm(1188): GC_FOR_ALLOC freed <1K, 7% free 7253K/7784K, paused 14ms, total 14ms
10-27 19:37:06.850: W/EGL_genymotion(1188): eglSurfaceAttrib not implemented
10-27 19:37:07.330: I/chromium(1188): [INFO:async_pixel_transfer_manager_android.cc(60)] Async pixel transfers not supported
10-27 19:37:07.406: I/chromium(1188): [INFO:async_pixel_transfer_manager_android.cc(60)] Async pixel transfers not supported
10-27 19:37:07.670: E/eglCodecCommon(1188): **** ERROR unknown type 0x238e0a (glSizeof,73)
10-27 19:37:07.678: I/Choreographer(1188): Skipped 30 frames! The application may be doing too much work on its main thread.
10-27 19:37:07.902: E/eglCodecCommon(1188): **** ERROR unknown type 0x238e0a (glSizeof,73)
10-27 19:37:07.986: W/EGL_genymotion(1188): eglSurfaceAttrib not implemented
10-27 19:37:08.102: E/eglCodecCommon(1188): **** ERROR unknown type 0x238e0a (glSizeof,73)
10-27 19:37:08.358: E/eglCodecCommon(1188): **** ERROR unknown type 0x238e0a (glSizeof,73)
10-27 19:37:12.870: W/System.err(1188): java.lang.NullPointerException
10-27 19:37:12.870: W/System.err(1188): at com.hostwr.ibrahemfeqy.WebViewClientDemoActivity$myWebClient.onPageFinished(WebViewClientDemoActivity.java:118)
10-27 19:37:12.870: W/System.err(1188): at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:455)
10-27 19:37:12.870: W/System.err(1188): at com.android.org.chromium.android_webview.AwContentsClient$AwWebContentsObserver.didFinishLoad(AwContentsClient.java:62)
10-27 19:37:12.870: W/System.err(1188): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
10-27 19:37:12.870: W/System.err(1188): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:24)
10-27 19:37:12.870: W/System.err(1188): at android.os.Handler.dispatchMessage(Handler.java:102)
10-27 19:37:12.870: W/System.err(1188): at android.os.Looper.loop(Looper.java:136)
10-27 19:37:12.870: W/System.err(1188): at android.app.ActivityThread.main(ActivityThread.java:5001)
10-27 19:37:12.870: W/System.err(1188): at java.lang.reflect.Method.invokeNative(Native Method)
10-27 19:37:12.870: W/System.err(1188): at java.lang.reflect.Method.invoke(Method.java:515)
10-27 19:37:12.870: W/System.err(1188): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
10-27 19:37:12.870: W/System.err(1188): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
10-27 19:37:12.870: W/System.err(1188): at dalvik.system.NativeStart.main(Native Method)
10-27 19:37:13.318: E/eglCodecCommon(1188): **** ERROR unknown type 0x238e0a (glSizeof,73)
10-27 19:37:13.330: W/Ads(1188): There was a problem getting an ad response. ErrorCode: 0
10-27 19:37:13.342: W/Ads(1188): Failed to load ad: 0
10-27 19:37:13.342: W/Ads(1188): There was a problem getting an ad response. ErrorCode: 0
10-27 19:37:13.362: W/Ads(1188): Failed to load ad: 0
請問你能否解釋你的第二段?你的意思是糟糕的用戶體驗?爲什麼谷歌應該禁止該帳戶?你怎麼稱呼它呢?你能提供一個例子嗎?謝謝 – 2015-09-01 13:33:53
它提供了一個糟糕的用戶體驗,因爲在用戶處於中間做某事時,突然顯示a。 Admob一直表示**不會執行此操作,並且此類行爲將導致帳戶被禁止。相反,您應該在應用程序的自然中斷點調用'displayInterstitial()'。 – William 2015-09-02 13:18:04
好了,現在我明白你的意思了。因爲(假設這不是一個聰明的模式),我認爲你嚴格地討論了代碼結構,開發人員可以選擇在某些用戶交互結束時加載「加載」,並直接顯示插入式代碼「onAdLoaded」。感謝您的洞察! – 2015-09-02 14:40:06