我已经集成到以编程方式查看广告,它似乎正在模拟器上工作,但不是在我的LG G3设备上,我重新检查我的整个代码,没有得到我错误的地方,...
这是我的广告活动页面代码:
public class TerrorKill extends Activity {
Surface view;
WakeLock WL;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//TODO: --------------------------------------------------------------------------change advert unit id
AdView ad = new AdView(this, AdSize.BANNER, "ca-app-pub-1114663329734183/8892144958");//enter advert id here
RelativeLayout layout = new RelativeLayout(this);
//layout
view = new Surface(this, this);
LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
ad.setLayoutParams(params1);
layout.addView(view);
layout.addView(ad);
setContentView(layout);
//TODO: ad-------------------------------------------------------------------------add testing devices if you wish
AdRequest request = new AdRequest();
/*request.addTestDevice("275D94C2B5B93B3C4014933E75F92565");///nexus7//////testing
request.addTestDevice("91608B19766D984A3F929C31EC6AB947"); /////////////////testing//////////////////remove///////////
request.addTestDevice("6316D285813B01C56412DAF4D3D80B40"); ///test htc sensesion xl
request.addTestDevice("8C416F4CAF490509A1DA82E62168AE08");//asus transformer
*/ ad.loadAd(request);
//wake-lock
PowerManager PM = (PowerManager) getSystemService(Context.POWER_SERVICE);
WL = PM.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Graphics");
WL.acquire();
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == 0)
view.default_lanscape = true;
if (rotation == 180)
view.default_lanscape = true;
if (rotation == 90)
view.default_lanscape = false;
if (rotation == 270)
view.default_lanscape = false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
if (keyCode == KeyEvent.KEYCODE_BACK) {
view.back();
return false;
}
return false;
}
protected void onPause() {
super.onPause();
view.pause();
WL.release();
}
protected void onResume() {
super.onResume();
view.resume();
WL.acquire();
}
@Override
protected void onDestroy() {
super.onDestroy();
WL.release();
}
}
这是我的Android宣言
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techom.TerrorKill"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
<activity
android:name="com.techom.terror.TerrorKill"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.techom.terror.EnterHiscore"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:-1)
要检查的事项: