显示Admob广告\ LocalStorage损坏

时间:2012-12-17 14:17:52

标签: cordova local-storage admob ads

第一篇文章,我感谢有很多关于这个主题的帖子,我已经搜索了答案。

我正在使用JQM(1.2),Cordova(2.2),Admob(6.2.1)开发Android应用程序,我的广告没有出现。

    public class cordovaExample extends DroidGap 
    {       
    private Handler mHandler = new Handler();
        private AdView adView;

     public void onCreate(Bundle savedInstanceState) 
     {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");

            mHandler.postDelayed(new Runnable()
            {
                public void run() 
                {           //      
                    doAdMob();
                }
            }, 5000);         
     }

     private void doAdMob() 
     {
            // Create the adView           
            adView = new AdView(this, AdSize.SMART_BANNER, "MYCODE");           
            LinearLayout layout = super.root;
            layout.addView(adView);
            layout.setHorizontalGravity(android.view.Gravity.CENTER_HORIZONTAL);
            AdRequest request = new AdRequest();
            adView.loadAd(request);   
     }               
}

以下是我的logcat的摘录:

12-17 14:07:06.424: I/Ads(24745): Refreshing ad.
12-17 14:07:06.454: I/Ads(24745): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":2,"session_id":"11970596199473559413","seq_num":"3","slotname":"a150bd20d174dce","u_w":360,"msid":"org.apache.cordova.example","js":"afma-sdk-a-v6.2.1","bas_off":0,"net":"ed","app_name":"1.android.org.apache.cordova.example","hl":"en","smart_w":"full","gnt":15,"carrier":"23430","u_audio":1,"u_sd":1.5,"mv":"8016010.com.android.vending","isu":"82D3E2C68BC8ABDE44C1EA123E7289AA","cipa":1,"format":"360x50_mb","oar":2,"smart_h":"auto","ad_pos":{"height":0,"visible":1,"y":888,"x":0,"width":540},"u_h":592,"bas_on":0,"ptime":120733});</script></head><body></body></html>
12-17 14:07:06.484: I/Ads(24745): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=2&session_id=11970596199473559413&seq_num=3&u_w=360&msid=org.apache.cordova.example&js=afma-sdk-a-v6.2.1&bas_off=0&net=ed&app_name=1.android.org.apache.cordova.example&hl=en&smart_w=full&gnt=15&carrier=23430&u_audio=1&u_sd=1.5&mv=8016010.com.android.vending&isu=82D3E2C68BC8ABDE44C1EA123E7289AA&cipa=1&format=360x50_mb&oar=2&smart_h=auto&u_h=592&bas_on=0&ptime=120733&u_so=p&output=html&region=mobile_app&u_tz=0&client_sdk=1&ex=1&slotname=a150bd20d174dce&askip=2&gsb=4g&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=41" type: "admob" afmaNotifyDt: "null" useWebViewLoadUrl: "false">
12-17 14:07:06.484: I/Ads(24745): Request scenario: Offline with no buffered ads.
12-17 14:07:06.484: I/Ads(24745): Network is unavailable.  Aborting ad request.
12-17 14:07:06.484: I/Ads(24745): onFailedToReceiveAd(A network error occurred.)
12-17 14:08:56.894: I/Ads(25453): To get test ads on this device, call adRequest.addTestDevice("82D3E2C68BC8ABDE44C1EA123E7289AA");
12-17 14:08:56.954: I/Ads(25453): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"8715359451090924487","seq_num":"1","slotname":"a150bd20d174dce","u_w":360,"msid":"org.apache.cordova.example","js":"afma-sdk-a-v6.2.1","bas_off":0,"net":"ed","app_name":"1.android.org.apache.cordova.example","hl":"en","smart_w":"full","gnt":15,"carrier":"23430","u_audio":1,"u_sd":1.5,"mv":"8016010.com.android.vending","isu":"82D3E2C68BC8ABDE44C1EA123E7289AA","cipa":1,"format":"360x50_mb","oar":0,"smart_h":"auto","ad_pos":{"height":0,"visible":1,"y":888,"x":0,"width":540},"u_h":592,"bas_on":0,"ptime":0});</script></head><body></body></html>
12-17 14:08:57.184: I/Ads(25453): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=8715359451090924487&seq_num=1&u_w=360&msid=org.apache.cordova.example&js=afma-sdk-a-v6.2.1&bas_off=0&net=ed&app_name=1.android.org.apache.cordova.example&hl=en&smart_w=full&gnt=15&carrier=23430&u_audio=1&u_sd=1.5&mv=8016010.com.android.vending&isu=82D3E2C68BC8ABDE44C1EA123E7289AA&cipa=1&format=360x50_mb&oar=0&smart_h=auto&u_h=592&bas_on=0&ptime=0&u_so=p&output=html&region=mobile_app&u_tz=0&client_sdk=1&ex=1&slotname=a150bd20d174dce&gsb=4g&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=41" type: "admob" afmaNotifyDt: "null" useWebViewLoadUrl: "false">
12-17 14:08:57.184: I/Ads(25453): Request scenario: Offline with no buffered ads.
12-17 14:08:57.184: I/Ads(25453): Network is unavailable.  Aborting ad request.
12-17 14:08:57.194: I/Ads(25453): onFailedToReceiveAd(A network error occurred.)

我认为这可能是我的布局有问题,因为广告视图高度始终为0,但我不确定。我确信Phonegap和Admob设置正确,因为如果我使用CordovaWebView我可以展示广告:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/rootLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <org.apache.cordova.CordovaWebView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"  
       android:layout_above="@+id/adView" 
        android:id = "@+id/mainView"/>

    <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignParentBottom="true"
                         ads:adUnitId="MYCODE"
                         ads:adSize="SMART_BANNER"                        
                         ads:loadAdOnCreate="true"/>    
</RelativeLayout >

不幸的是,由于这个错误,如果我不延迟添加adview https://github.com/phonegap/phonegap/wiki/In-App-Advertisements

,我的本地存储就会被删除

简而言之,任何人都可以使用.java,main.xml来处理Phonegap,admob和本地存储。

1 个答案:

答案 0 :(得分:0)

我认为你应该在布局文件中编写这段代码:

<com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="YOUR_ID"
    />