我使用libgdx創建一個遊戲,我完成了編碼和一切工作 但是當我實現廣告它不出現廣告不會出現在我的應用程序(使用libgdx)
這是我MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;
import com.google.ads.AdRequest;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.*;
import com.pixelstudioz.RevengeOfTheTunnels.ROTTGame;
public class MainActivity extends AndroidApplication{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
//setContentView(R.layout.main);
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams gameViewParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
//gameViewParams.bottomMargin = 150;
requestWindowFeature(Window.FEATURE_NO_TITLE);
View gameView = initializeForView(new ROTTGame(), cfg);
layout.addView(gameView, gameViewParams);
AdView adView = new AdView(this);
adView.setAdUnitId("YOUR ADMOB AD ID");
//adView.setAdUnitId("app-id");
adView.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView, adParams);
com.google.android.gms.ads.AdRequest request = new com.google.android.gms.ads.AdRequest.Builder()
.addTestDevice(AdRequest.TEST_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
adView.loadAd(request);
setContentView(layout);
initialize(new ROTTGame(), cfg);
}
}
,這是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
package="com.package.appname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name="com.google.android.gms.samples.ads.GoogleAdsSampleActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.pixelstudioz.RevengeOfTheTunnels.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
,這是我layout.xml
<?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"
>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="unitid"
ads:adSize="SMART_BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"/>
</LinearLayout>
請幫助 我首先需要應用程序ID ???像admob?或者是什麼?? ANW檢查代碼,並thanksss
所以我需要做的是去除初始化(新的ROTTGame(),cfg)或initializeForView() – samirifai
之後我需要做什麼來顯示廣告??謝謝 – samirifai
我是否需要讓應用ID顯示廣告? – samirifai