我真的被困在这里,试图用ads-admob设置横幅到我的Android应用程序。我已经完成了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无法解析”。我的档案:
我的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>
有没有人经历过这样的事情?
答案 0 :(得分:1)
请阅读Android版Google AdMob SDK的getting started指南。您获得该代码的示例来自Google AdMob Ads SDK重写之前的旧版Google广告SDK。
我在第一次传球时可以看到的问题:
答案 1 :(得分: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工作了......但是! YE,有一个但是...... 2天之后,凭借令人难以置信的$ 0,00和150个广告请求,admob / google取消了我的帐户!我听说他们的方法很奇怪并且完全没有任何理由删除开发人员,并且以0,00美元和150美元的观看次数将他们从他们的计划中删除。好的部分:我发现其他一些广告服务比admob更好,但负面的是我将不得不再次找出代码......
谢谢Eric!