Admob集成到Android应用程序中 [英] Admob Integration into Android Application

查看:195
本文介绍了Admob集成到Android应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约一年前,我开始对Android应用进行编程,但从未将Admob广告集成到应用中。首先,我使用Android SDK Manager(2015年1月)将工具,文档,SDK平台,示例,API和其他功能(Android支持库和Google Play服务)更新为最新版本。看来旧的AdMob 6.4.1已不再使用,并已由Google Play服务取代。



基于Google移动广告文档[htpps:// developer.android.com/google/play-services/ads.html],我将位于 / extras / google / google-google-google-google-google-play-services / samples / admob /的示例下载并导入了Eclipse。



Java示例充满了错误。两个示例Java类(GoogleAdsSampleActivity.java和BannerXmlActivity.java)中的每一行都有错误。导入行指出导入com.google.android.gms.ads无法解析。提供的7个快速修复程序均不能解决问题。我完全不知道下一步该怎么做。我已经尝试过Google搜索来寻找答案,但是却无济于事。我尝试了Project Clean and Build All,但没有帮助。谁能为我提供一些指导。谢谢。

解决方案

我试图将广告集成到我的android应用中,现在我已经实现了。
以下是步骤。



1。您需要有一个Gmail帐户。



2 。打开www.admob.com



3。登录Admob链接将在那里。



4使用您的gmail用户名和密码登录。



5。登录后,系统会要求您填写一些表格。



6。填充后,您将进入一个新页面,其中会有一个名为货币化的选项。



7。在货币化下,您单击货币化



8。在那里选择手动添加应用。



9。输入应用名称并选择平台。



10。现在转到选择广告格式和名称广告单元。



11 。选择横幅广告。



12。键入广告单元名称。



13。单击保存。 / p>

14。您将获得广告单元ID,通常以ca开头,您需要记下该代码以供将来在应用中使用。



这些是第一步的操作步骤。
接下来,您必须在android代码中执行它。我正在使用eclipse。



1。打开eclipse。



2。创建新的Android应用程序项目。



3。下载GoogleAdMobAdsSdk-4.1.1.jar



4。将该jar包含在您的项目的库中。



5。现在,右键单击项目,转到属性,然后单击 Java Build,转到,库,转到,添加jar,选择您最近添加到库中的jar。单击确定并退出。



6。现在打开AndroidManifest.xml您的项目。对应用程序标签上方的文件包括以下两个权限。

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

7。在内部,您必须按以下方式声明AdActivity

 < application> 



< activity
android:name = com.google.ads.AdActivity
android:configChanges = keyboard | keyboardHidden | orientation | screenLayout | uiMode | screenSize | smallestScreenSize
android:theme = @ android:style / Theme.Translucent />



< / application>

8。打开xml布局activity_main并粘贴以下代码。

 < com.google.ads.AdView 
xmlns:googleads = http://schemas.android.com/apk/lib/com.google .ads
android:id = @ + id / ad
android:layout_width = fill_parent
android:layout_height = wrap_content
android:layout_alignParentBottom = true
googleads:adSize = BANNER
googleads:adUnitId =您的添加单位ID />

请注意googleads:adUnitId的值将是您使用admob.com生成的ID。我已经请您记下它了。希望您记得。



9。打开MainActivity,将以下代码粘贴到oncreate

  AdView mAdView; 

oncreate()
{
mAdView =(AdView)findViewById(R.id.ad);
mAdView.setAdListener(new MyAdListener());

AdRequest adRequest = new AdRequest();
adRequest.addKeyword(体育用品);
mAdView.loadAd(adRequest);
}

10。在MainActivity中添加以下代码作为内部类

 私有类MyAdListener实现AdListener {

@Override
public void onFailedToReceiveAd(Ad ad,ErrorCode errorCode ){

}

@Override
public void onReceiveAd(Ad ad){

}

@Override
public void onDismissScreen(Ad arg0){
// TODO自动生成的方法存根

}

@Override
public void onLeaveApplication(Ad arg0){
// TODO自动生成的方法存根

}

@Override
public void onPresentScreen(Ad arg0){
// TODO自动生成的方法存根

}
}

完成。尝试上面的操作,让我知道反馈。



谢谢



负债


I started programming Android apps about a year ago but have never integrated the Admob ad into an app. To get started, I used the Android SDK Manager (Jan, 2015) to update the Tools, Documentation, SDK platform, samples, APIs, and Extras (Android Support Library and Google Play Services) to the latest revisions. It looks like the old AdMob 6.4.1 is no longer used and has been replaced with the Google Play Services.

Based on the Google Mobile Ads documentation [ htpps://developer.android.com/google/play-services/ads.html ], I downloaded and imported into Eclipse the sample located at "/extras/google/google-play-services/samples/admob/".

The Java sample is full of errors. Every line in the two sample Java classes (GoogleAdsSampleActivity.java and BannerXmlActivity.java) has an error. The import lines state that "The import com.google.android.gms.ads cannot be resolved". None of the 7 quick fixes available solves the problem. I'm at a complete loss as to what to do next. I've tried Google search for an answer but got nowhere. I tried Project Clean and Build All and no help. Can anyone provide me with some direction. Thanks.

解决方案

I was trying to integrate ads into my android app and now I have achieved it. Below are the steps.

1.You need to have a gmail account.

2.Open www.admob.com

3."Sign Into Admob" link will be there.

4.Sign In using your gmail username and password.

5.After login you will be asked to fill some forms.

6.After filling you will be taken to a new page where there will be a option called "Monetize".

7.Under Monetize you have click "Monetize a new app".

8.There select "Add App Manually".

9.Type App Name and select Platform.

10.Now go to "Select ad format and name ad unit".

11.Select "Banner".

12.Type an Ad Unit name.

13.Click Save.

14.You will get "Ad Unit Id" which usually starts with ca-You have to note down it for future use in app.

These are the steps you have follow as a first step. Now the next steps,you have to perform it in android code.I am using eclipse.

1.Open eclipse.

2.Create new Android Application Project.

3.Download GoogleAdMobAdsSdk-4.1.1.jar

4.Include that jar in libs of your project.

5.Now right click project,go to,Properties,got to,Java Build,go to,Libraries,go to,Add jars,Select the jar that you recently added to the libs.Click ok and exit.

6.Now open AndroidManifest.xml of you project.Include the below two permission to the file above application tag.

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

7.Inside you have to declare AdActivity as follows

<application>
.
.
.
 <activity
 android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
 android:theme="@android:style/Theme.Translucent" />
.
.
.
</application>

8.Open xml layout activity_main and paste the following code.

 <com.google.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        googleads:adSize="BANNER"
        googleads:adUnitId="Your Add unit id" />

Please note the value for googleads:adUnitId will be the id which you have generated using admob.com.I have asked you to note it down before.Hope u remember.

9.Open MainActivity ,paste the following code in oncreate

AdView mAdView;

oncreate()
{
        mAdView = (AdView) findViewById(R.id.ad);
        mAdView.setAdListener(new MyAdListener());

        AdRequest adRequest = new AdRequest();
        adRequest.addKeyword("sporting goods");
        mAdView.loadAd(adRequest);
}

10.Add the following code in the MainActivity as an inner class

private class MyAdListener implements AdListener {

        @Override
        public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {

        }

        @Override
        public void onReceiveAd(Ad ad) {

        }

        @Override
        public void onDismissScreen(Ad arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLeaveApplication(Ad arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPresentScreen(Ad arg0) {
            // TODO Auto-generated method stub

        }
    }

Finished.Try the above and let me know the feedback.

Thanks

Lincy

这篇关于Admob集成到Android应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆