Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admob use googleplay-service #99

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion plugins/admob/proj.android/ForManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifestConfig xmlns:android="http://schemas.android.com/apk/res/android">
<applicationCfg keyword="com.google.ads.AdActivity">
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</applicationCfg>

<permissionCfg>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</permissionCfg>
</manifestConfig>
<!--
You have to add
android.library.reference.2=relative/path/to/extras/google/google_play_services/libproject/google-play-services_lib
to your project.properties
-->
65 changes: 33 additions & 32 deletions plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Iterator;
import java.util.Set;

import com.google.ads.*;
import com.google.ads.AdRequest.ErrorCode;
import com.google.android.gms.ads.*;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.WindowManager;
qimport android.view.WindowManager;

public class AdsAdmob implements InterfaceAds {

Expand Down Expand Up @@ -169,36 +168,39 @@ public void run() {
size = AdSize.BANNER;
break;
case AdsAdmob.ADMOB_SIZE_IABMRect:
size = AdSize.IAB_MRECT;
size = AdSize.MEDIUM_RECTANGLE;
break;
case AdsAdmob.ADMOB_SIZE_IABBanner:
size = AdSize.IAB_BANNER;
size = AdSize.BANNER;
break;
case AdsAdmob.ADMOB_SIZE_IABLeaderboard:
size = AdSize.IAB_LEADERBOARD;
size = AdSize.LEADERBOARD;
break;
case AdsAdmob.ADMOB_SIZE_Skyscraper:
size = AdSize.IAB_WIDE_SKYSCRAPER;
size = AdSize.WIDE_SKYSCRAPER;
break;
default:
break;
}
adView = new AdView(mContext, size, mPublishID);
AdRequest req = new AdRequest();
adView = new AdView(mContext);
adView.setAdSize(size);
adView.setAdUnitId(mPublishID);
AdRequest.Builder req = new AdRequest.Builder();

try {
if (mTestDevices != null) {
req = req.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
Iterator<String> ir = mTestDevices.iterator();
while(ir.hasNext())
{
req.addTestDevice(ir.next());
req = req.addTestDevice(ir.next());
}
}
} catch (Exception e) {
LogE("Error during add test device", e);
}

adView.loadAd(req);
adView.loadAd(req.build());
adView.setAdListener(new AdmobAdsListener());

if (null == mWm) {
Expand Down Expand Up @@ -232,51 +234,50 @@ public void addTestDevice(String deviceID) {
mTestDevices.add(deviceID);
}

private class AdmobAdsListener implements AdListener {
private class AdmobAdsListener extends AdListener {

@Override
public void onDismissScreen(Ad arg0) {
LogD("onDismissScreen invoked");
AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_AdsDismissed, "Ads view dismissed!");
public void onAdClosed() {
LogD("onAdClosed invoked");
AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_AdsDismissed, "Ads view closed!");
}

@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
public void onFailedToLoad(int errorCode) {
int errorNo = AdsWrapper.RESULT_CODE_UnknownError;
String errorMsg = "Unknow error";
switch (arg1) {
case NETWORK_ERROR:
switch (errorCode) {
case AdRequest.ERROR_CODE_NETWORK_ERROR:
errorNo = AdsWrapper.RESULT_CODE_NetworkError;
errorMsg = "Network error";
break;
case INVALID_REQUEST:
case AdRequest.ERROR_CODE_INVALID_REQUEST:
errorNo = AdsWrapper.RESULT_CODE_NetworkError;
errorMsg = "The ad request is invalid";
break;
case NO_FILL:
case AdRequest.ERROR_CODE_NO_FILL:
errorMsg = "The ad request is successful, but no ad was returned due to lack of ad inventory.";
break;
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
errorMsg = "The ad request is internal error";
break;

default:
break;
}
LogD("failed to receive ad : " + errorNo + " , " + errorMsg);
LogD("failed to load ad : " + errorNo + " , " + errorMsg);
AdsWrapper.onAdsResult(mAdapter, errorNo, errorMsg);
}

@Override
public void onLeaveApplication(Ad arg0) {
LogD("onLeaveApplication invoked");
public void onAdLeftApplication() {
LogD("onAdLeftApplication invoked");
}

@Override
public void onPresentScreen(Ad arg0) {
LogD("onPresentScreen invoked");
public void onAdOpened() {
LogD("onAdOpened invoked");
AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_AdsShown, "Ads view shown!");
}

@Override
public void onReceiveAd(Ad arg0) {
LogD("onReceiveAd invoked");
public void onAdLoaded() {
LogD("onAdLoaded invoked");
AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_AdsReceived, "Ads request received success!");
}
}
Expand Down