1

4.0.4 エミュレーターと 4.0.4 スマートフォンで Admob を表示することに成功しましたが、2.1 エミュレーターを実行して 2.1 スマートフォンで試してみると、「ネットワークがありません」というエラーが表示され、何も表示されません。

04-10 10:33:38.683: I/Ads(256): Network is unavailable.  Aborting ad request.
04-10 10:33:38.693: D/webviewglue(256): nativeDestroy view: 0x73eac0
04-10 10:33:38.693: I/Ads(256): onFailedToReceiveAd(A network error occurred.)
04-10 10:33:38.693: W/webcore(256): Can't get the viewWidth after the first layout

これは私が使用しているコードです:

public class MyPhoneGapActivity extends DroidGap {

private Handler mHandler = new Handler();
private AdView adView;
/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {

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

    mHandler.postDelayed(new Runnable() {
        public void run() {
            doStuff();
        }
    }, 5000); 
}
private void doStuff() {
    final String MY_AD_UNIT_ID = "MY_ID";
    AdView adView; 
    // Create the adView 
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID); 
    LinearLayout layout = super.root; // this is the only change from the sample 
    // Add the adView to it 
    layout.addView(adView); 
    // Initiate a generic request to load it with an ad 
    adView.loadAd(new AdRequest());
} 

マニフェスト:

<uses-sdk android:minSdkVersion="7" 
android:targetSdkVersion="13"/>

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />

  <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

プロジェクトのプロパティ

target=android-13

android:configChanges を以下のように変更すると、広告バナーが表示されますが、「構成の変更を伴う android manifest.xml で adActivity を宣言する必要があります。

 <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|" /> 

ありがとう

4

0 に答える 0