我真的被困在这里,试图在我的 android 应用程序中设置一个带有 ads-admob 的横幅。我已经完成了 main.xml 中的所有布局设置,还在清单文件中使用了权限,尝试了 XML 和 JAVA 方法来显示广告并试图使其工作,但我总是从“无法获取 currentAdManager” Eclipse 中的 logcat。该应用程序也在这里崩溃,但没有 admob 设置也能正常工作。我的 admob SDK 是 GoogleAdMobAdsSdk-6.0.1.jar,我正在使用 phonegap 进行开发。
我注意到命令“import com.google.ads.*;” 没有“AdManager”,因为当我单独插入“import com.google.ads.AdManager;”时,我收到错误消息“无法解析导入 com.google.ads.AdManager”。我的文件:
我的爪哇:
> 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());
> }
> }
我的布局文件(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>
有没有人已经经历过这样的事情?