PhoneGap的使用播放服务广告 [英] Phonegap use Play Services for Ads
问题描述
随着谷歌逐步淘汰专用Admob的SDK支持播放服务SDK我怎么能整合广告到我的PhoneGap应用程序与游戏服务的?不久Admob的SDK应用程序甚至不会在Play商店允许的。
With Google phasing out the dedicated Admob SDK in favour of the Play Services SDK how can I integrate ads into my Phonegap app with Play Services? Soon Admob SDK apps won't even be allowed in the Play Store.
感谢
推荐答案
我在不久前想通了这一点,但想我应该回到这里回答这个柜面任何人想知道在这个问题。但愿我包括需要得到这个工作的一切。
I figured this out a while ago, but figured I should come back here and answer this incase anyone wonders upon this question. Hopefully I'm including everything needed to get this working.
首先,你需要将包括谷歌,播放services_lib在你的项目。
First you need to be including google-play-services_lib in your project.
然后在你的主类(会像phoneGapAppName /平台/安卓/ src目录/ COM / MYNAME /对myApp / myApp.java)
Then in your main class (will be something like phoneGapAppName/platforms/android/src/com/ myname/myApp/myApp.java)
根据科尔多瓦进口(进口org.apache.cordova *;
。)地址:
Under the cordova import (import org.apache.cordova.*;
) add:
import android.view.WindowManager;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
然后在您的主要公共类(类似公共类对myApp扩展CordovaActivity
)的东西,如替换默认code:
Then in your main public class (something like public class myApp extends CordovaActivity
) replace the default code with something like:
private AdView mAdView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
mAdView = new AdView(this);
mAdView.setAdUnitId("YOUR_ADD_UNIT_CODE");
mAdView.setAdSize(AdSize.BANNER);
LinearLayout layout = super.root;
layout.addView(mAdView);
layout.setHorizontalGravity(android.view.Gravity.CENTER_HORIZONTAL);
mAdView.loadAd(new AdRequest.Builder().build());
}
@Override
protected void onPause() {
mAdView.pause();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
mAdView.resume();
}
您可能还需要像这样添加到您的的AndroidManifest.xml
:
You may also have to add something like this to your AndroidManifest.xml
:
<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"/>
这是我做的,它完美的作品对我来说,你需要适应到您自己的应用程序,并找出了一些它自己的,但是这是一个很好的起点。
This is what I did and it works perfectly for me, you will need to adapt this to your own app and figure out some of it on your own, but this is a good starting point.
这篇关于PhoneGap的使用播放服务广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!