首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入com.google.ads.*;没有AdManager

导入com.google.ads.*;没有AdManager
EN

Stack Overflow用户
提问于 2012-06-19 02:08:50
回答 2查看 2.4K关注 0票数 1

我真的被困在这里了,试图在我的android应用程序上设置一个广告-admob横幅。我已经完成了main.xml中的所有布局设置,也在清单文件中使用了权限,尝试了XML和JAVA方法来显示广告,并试图使其正常工作,但在Eclipse中,我总是从logcat获得“无法获取currentAdManager”。这个应用程序在这里也会崩溃,但是在没有admob设置的情况下可以正常工作。我的admob是GoogleAdMobAdsSdk-6.0.1.jar,我正在使用phonegap进行开发。

我注意到命令"import com.google.ads.*;“没有"AdManager”,因为当我单独插入"import com.google.ads.AdManager;“时,会收到”导入com.google.ads.AdManager无法解析“的错误消息。我的档案:

My:

代码语言:javascript
复制
>     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):

代码语言:javascript
复制
>     <?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>

我的舱单:

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
> <?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>

有人已经经历过这样的事情吗?

EN

回答 2

Stack Overflow用户

发布于 2012-06-21 18:53:32

请阅读谷歌AdMob SDK的AdMob指南。在Google重写之前,您可以从一个旧的Google中获得代码。

我第一次看到的问题是:

  1. 您的活动定义是不正确的。有关正确的此页活动定义,请参见AdActivity。
  2. 你不需要attrs.xml。SDK现在包括这些属性。
  3. 我不认为出版商的身份可以是一个元-山谷。必须在AdView XML定义中指定publisher id。
  4. 您的AdView XML定义需要一个adSize。
  5. 新的Google没有AdMob类。
票数 1
EN

Stack Overflow用户

发布于 2012-06-29 01:20:37

谢谢埃里克!你的回答帮助我找到了正确的密码。最终代码如下所示:

爪哇:

代码语言:javascript
复制
   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()); 

    }    
    }

我的布局:

代码语言:javascript
复制
   <?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从那时起就开始工作..。但!是的有一个但是..。两天后,以惊人的金额,$0,00和150广告的渴望,admob/谷歌取消了我的帐户!我听说他们的方法很奇怪,而且毫无理由地删除了开发人员,并且有了$0,00和150的浏览量,他们把我从他们的程序中删除了。好的部分:我发现了一些比admob更好的广告服务,但不好的方面是,我需要重新计算代码.

不管怎样,谢谢埃里克!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11093492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档