1. Introduce
Now the ads in the game have basically become an important source of revenue for game creators. In fact, the insertion of advertising is quite simple, this article chose the Baidu Advertising Alliance as a case (always feel that Baidu will not pay wages). Note: However, the insertion of the ad program will be a little bit more card, and really very traffic.
(This article is not copy Baidu's document, will be very straightforward OH)
2. The Code section
First of all must be registered Baidu Advertising Alliance account, and download SDK. Address: http://munion.baidu.com/
The second step is to open Eclipse and import the inside jar file into the library.
Copy the jar package from Baidu to the Libs directory of your project, and import it in the following steps:
Right-click on your project and choose Properties.
Select Java build Path on the left side of the Project Properties dialog box.
In the Project Properties dialog box main window select "Libraries";
Click "Add JARs", add Baidu to promote jar package.
(In fact, I tried, directly copy the jar paste into Lib can also)
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
The third step is to modify the permissions in the Androidmainfest.xml. (Annotated place is the place to add)
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/" Android "package=" Com.example.adtest "android:versioncode=" 1 "android:versionname=" 1.0 "> < USES-SDK android:minsdkversion= "8" android:targetsdkversion= "a"/> <span style= "color: #ff6666" ><uses-permission android:name= "Android.permission.INTERNET"/> </span><span style= " Color: #ff6666 "> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> <uses-perm Ission android:name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name= "Android.perm" Ission.
Access_coarse_location "/> <uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/>" <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/></span> <appl Ication Android:allOwbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:them E= "@style/apptheme" > <span style= "color: #3366ff" ><meta-data android:name= "baidumobad_app_id" Androi d:value= "Debug"/> <meta-data android:name= "baidumobad_app_sec" android:value= "Debug"/> </span > <span style= "color: #33ff33" ><activity android:name= "com.baidu.mobads.AppActivity" android:c onfigchanges= "Keyboard|keyboardhidden|orientation"/> </span> <activity and Roid:name= "com.example.adtest.MainActivity" android:label= "@string/app_name" > <intent-fil ter> <action android:name= "Android.intent.action.MAIN"/> <categor
Y android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application&gT </manifest>
The permission area is filled with permissions. Meta-data is to add Baidu account, we suggest that the value of debug for debugging, debug the end of their own.
<span style= "Color:rgb (51,255,51)" ><activity android:name= "com.baidu.mobads.AppActivity"
android: Configchanges= "Keyboard|keyboardhidden|orientation" /></span>
Area can be added directly.
Get Appsid and Appsec. Click "Upload Application" on the image above to see the "Application Version list" below
The fourth step, Baidu provides a variety of advertising models, where the choice of roulette, feeling is the simplest kind. is to modify it in creat ().
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Relativelayout rlmain=new Relativelayout (this);
Setcontentview (rlmain);
Iconsad iconsad=new Iconsad (this);
Iconsad.loadad (this);
}
SOURCE Download Address