我在Android应用中使用Webview。当我运行应用程序时,第一次运行时不显示admob。如果我再次运行应用程序,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("XXXXXXXXXXXXXX");
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("XXXXXXXXXXXXXX");
interstitial.show();
}
});
if(isNetworkStatusAvialable (getApplicationContext())) {
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("XXXXXXXXXXXXXXXXXX");
} 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;
}
}
Log Cat
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
答案 0 :(得分:0)
你不应该在onAdLoaded()中有displayInterstitial()。这导致广告的结果仅在您第二次打开应用时显示。它可能会以不受欢迎的方式向您的用户显示广告(针对开发人员的需求)。只需在完成关卡或用户执行某些操作后使用displayInterstitial()。
答案 1 :(得分:0)
如果有人目前也遇到同样的问题。我想,我建议您查看您的admob帐户,您可能会发现需要修改自己的PIN码,以便广告开始展示。
希望这有助于某人。