1

ads-admob を使用して Android アプリにバナーを設定しようとして、私は本当にここで立ち往生しています。main.xml ですべてのレイアウト設定を行い、権限を使用してマニフェスト ファイルで作業し、XML と Java の両方のメソッドを試して広告を表示し、それを機能させようとしましたが、常に「currentAdManager を取得できませんでした」というメッセージが表示されます。 Eclipse の logcat。ここでもアプリケーションがクラッシュしますが、admob の設定がなくても問題なく動作します。私の admob SDK は GoogleAdMobAdsSdk-6.0.1.jar で、 phonegap を使用して開発しています。

コマンド「import com.google.ads.*;」に気付きました。「インポート com.google.ads.AdManager;」を個別に挿入すると、「インポート com.google.ads.AdManager を解決できません」というエラー メッセージが表示されるため、「AdManager」がありません。私のファイル:

私のJAVA:

>     package what.car.notes;
>     
>     import android.os.Bundle;
>     import org.apache.cordova.*;
>     import com.google.ads.AdView;
>     import com.google.ads.AdManager; **- ERROR APEARS HERE**
>     import com.google.ads.*;
>     
>     public class Cargeous21forActivity extends DroidGap {
>         /** Called when the activity is first created. */
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>             super.onCreate(savedInstanceState);
>             super.loadUrl("file:///android_asset/www/index.html");
>             setContentView(R.layout.main);
>             
>             dView adView = (AdView)this.findViewById(R.id.AdView);
>       adView.loadAd(new AdRequest());
>         }
>     }

私のLAYOUTファイル(main.xml):

>     <?xml version="1.0" encoding="utf-8"?>
>     
>     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
>         xmlns:myapp="http://schemas.android.com/apk/res/what.car.notes"
>       android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>         android:orientation="vertical">
>         
>     <com.admob.android.ads.AdView
>     android:id="@+id/AdView"
>     android:layout_width="fill_parent"
>     android:layout_height="wrap_content"
>     myapp:backgroundColor="#000000"
>     myapp:primaryTextColor="#FFFFFF"
>     myapp:secondaryTextColor="#CCCCCC"
>     /> 
>     
>     </LinearLayout>

私のマニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="what.car.notes"
android:versionCode="4"
android:versionName="1.3" >

<uses-sdk android:minSdkVersion="7" />
<uses-library
    android:name="com.google.ads.AdManager" />

<supports-screens 
android:largeScreens="true" 
android:normalScreens="true" 
android:smallScreens="true" 
android:resizeable="true" 
android:anyDensity="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

<meta-data android:value="i've put my correct id here" android:name="ADMOB_PUBLISHER_ID" />

<activity android:name="com.admob.android.ads.AdMobActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|keyboardHidden"
                android:value="SQLite-NDK"  />
        <!-- Track Market installs -->
<receiver android:name="com.admob.android.ads.analytics.InstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

最後に、attrs.xml:

> <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable
> name="com.admob.android.ads.AdView"> <attr name="backgroundColor"
> format="color" /> <attr name="primaryTextColor" format="color" />
> <attr name="secondaryTextColor" format="color" /> <attr
> name="keywords" format="string" /> <attr name="refreshInterval"
> format="integer" /> </declare-styleable> </resources>

誰かがすでにそのようなことを経験したことがありますか?

4

2 に答える 2

1

Android 向け Google AdMob SDK のスタートガイドをお読みください。そのコードを取得した例は、Google AdMob Ads SDK が書き直される前の古い Google 広告 SDK のものです。

最初のパスで確認できる問題:

  1. マニフェストのアクティビティ定義が正しくありません。AdActivity アクティビティの正しい定義については、このページを参照してください。
  2. attrs.xml は必要ありません。SDK には現在、これらの属性が含まれています。
  3. パブリッシャー ID をメタ値にすることはできないと思います。AdView XML 定義でサイト運営者 ID を指定する必要があります。
  4. AdView XML 定義には adSize が必要です。
  5. 新しい Google AdMob SDK には com.google.ads.AdManager クラスがありません。
于 2012-06-21T18:53:32.160 に答える
0

エリック、ありがとう!あなたの答えは私が正しいコードを見つけるのに大いに役立ちました。最終的なコードは次のようになります。

JAVA:

   import android.os.Bundle;
import org.apache.cordova.*;
import android.app.Activity;
import android.os.Handler;
import com.google.ads.*;
import android.widget.*;
import android.widget.LinearLayout; 


public class myactActivity extends DroidGap {

     private static final String MY_AD_UNIT_ID = "a14fd7e04e46295"; 
     private AdView adView; 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

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


        //
     // 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()); 

    }    
    }

私のレイアウト:

   <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

<com.google.ads.GoogleAdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    ads:adUnitId="xxxxxxxxxxxxxxxxxxxx" 
    ads:adSize="BANNER"
    ads:loadAdOnCreate="true"/> 

</LinearLayout>

それ以来、EVerthingは機能しました...しかし!ええ、ありますが... 2日後、$ 0,00の信じられないほどの金額と150の広告勧誘で、admob/googleは私のアカウントをキャンセルしました!! 彼らの方法は奇妙で、理由もなく開発者を削除すると聞いていました。$ 0,00と150のビューで、彼らは私を彼らのプログラムから切り離しました。良い部分:AdMobよりも優れた他の広告サービスをいくつか見つけましたが、マイナス面は、コードをもう一度理解する必要があることです...

とにかくありがとうエリック!

于 2012-06-29T01:20:37.917 に答える