4
測試插頁式廣告正在我的模擬器上工作。但他們不適合我的真實設備。應用未能在我的真實設備上加載插頁式廣告
獲取廣告響應時出現問題。 ErrorCode: 0
W/Ads: Failed to load ad: 0
我對onNavigationItemSelected
這裏呼籲mInterstitialAd.show();
是我的主要活動代碼
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, OddsConversionFragment.OnFragmentInteractionListener,
KellyCalculatorFragment.OnFragmentInteractionListener, PoissonCalculatorFragment.OnFragmentInteractionListener,
TrixieFragment.OnFragmentInteractionListener{
private static final String TAG = "ANALYTICS";
private Tracker mTracker;
InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupDrawerToolbar();
createAndAddFragment();
// Obtain the shared Tracker instance.
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
//Ads
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-82304873078*******"); //My Ad ID
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
requestNewInterstitial();
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("2CDE4B2B9E906AA1AB8A4EF9690AA6B9")
.build();
//2CDE4B2B9E906AA1AB8A4EF9690AA6B9 Device ID for
mInterstitialAd.loadAd(adRequest);
}
private void createAndAddFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
OddsConversionFragment oddsConversionFragment = new OddsConversionFragment();
fragmentTransaction.add(R.id.fragment_container, oddsConversionFragment);
fragmentTransaction.commit();
}
private void replaceFragment(Fragment fragment)
{
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
private void setupDrawerToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle(getString(R.string.odds_calculator));
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_close)
.setTitle("Closing Application")
.setMessage("Are you sure you want to close the app?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_oddsCalculator) {
replaceFragment(new OddsConversionFragment());
setToolbarTitle(getString(R.string.odds_calculator));
showScreen(getString(R.string.odds_calculator));
} else if (id == R.id.nav_kellyCalculator) {
replaceFragment(new KellyCalculatorFragment());
setToolbarTitle(getString(R.string.kelly_calculator));
showScreen(getString(R.string.kelly_calculator));
} else if (id == R.id.nav_poissonCalculator) {
replaceFragment(new PoissonCalculatorFragment());
setToolbarTitle(getString(R.string.poisson_calculator));
showScreen(getString(R.string.poisson_calculator));
} else if (id == R.id.nav_trixie_calculator) {
replaceFragment(new TrixieFragment());
setToolbarTitle(getString(R.string.trixie_calculator));
showScreen(getString(R.string.trixie_calculator));
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void showScreen(String screenName) {
Log.i(TAG, "Setting screen name: " + screenName);
mTracker.setScreenName(screenName);
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
private void setToolbarTitle(String name) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(name);
}
@Override
public void onFragmentInteraction(Uri uri) {
}
任何幫助將非常感激。
它位於Firebase Admob SDK指南的「入門」標籤:) – Jaeger
是的,我錯過了它!直接進入插頁式指南,因爲我不會使用橫幅xD – AresProductions
是的,這裏也一樣,不得不查看sdk指南,直到我看到那一步。 – Jaeger