2014-02-10 2 views
0

Добрый день, я пытаюсь увидеть мой прием, но это невозможно. ЭТО МОЯ MAIN_ACTIVITY.JAVA упаковка net.canarolab.puzzleroad;Я не могу видеть admob в моей игре

import android.app.Activity; 
import android.content.Intent; 
import android.media.AudioManager; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.LinearLayout; 
import android.widget.Toast; 

import com.google.ads.AdRequest; 
import com.google.ads.AdSize; 
import com.google.ads.AdView; 

public class MainActivity extends Activity { 
    // private AdView adView; 
    private MainView mainView; 
    private final int MENU_SELECT_RESET = 1, MENU_SELECT_CONTACT = 2; 

    // MUSICA 
    MediaPlayer mediaPlayer;// para musica de fondo (se declara aqui para que 
          // pueda 

    // utilizarla todos nuestros metodos) 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // MUSIC 
     mediaPlayer = MediaPlayer.create(this, R.raw.merry); 
     mediaPlayer.setLooping(true); 
     mediaPlayer.setVolume(100, 100); 
     mediaPlayer.start(); 

     // Apago la barra de título 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     // Apago la barra de estado 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     Intent i = getIntent(); 
     // Activity Quiero solo tapa 
     i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     setVolumeControlStream(AudioManager.STREAM_MUSIC); 
     // View Establezca el 
     mainView = new MainView(this); 
     // setContentView(mainView); 

     setContentView(R.layout.activity_main); 

      // ADMOB 
     LinearLayout layout = (LinearLayout) findViewById(R.id.mainView); 

     LinearLayout layout1 = (LinearLayout) findViewById(R.id.linearLayout1); 

     // Create the adView 
     // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID 
     AdView adView = new AdView(this, AdSize.BANNER, "a14e2f8fe3af5a6"); 

     // Add the adView to it 
     layout1.addView(adView); 

     // Initiate a generic request to load it with an ad 
     AdRequest request = new AdRequest(); 
     request.setTesting(true); 

     adView.loadAd(request); 

     // Lookup R.layout.main 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     // getMenuInflater().inflate(R.menu.activity_main, menu); 
     menu.add(0, MENU_SELECT_RESET, 0, "Reset"); 
     menu.add(0, MENU_SELECT_CONTACT, 0, "Contact"); 
     return true; 

    } 

    @Override 
    protected void onResume() { 
     mediaPlayer.start(); 

     // Leí el recuento juego 
     this.mainView.gameCount.read(); 
     Log.d("", "read"); 
     super.onResume(); 

    } 

    @Override 
    protected void onPause() { 
     mediaPlayer.pause(); 

     // Escribo el recuento de juego. 
     this.mainView.gameCount.save(); 
     Log.d("", "save"); 

     super.onPause(); 
     // No voy a desaparecer en esta actitud no hay más. 
     // finish(); 

    } 

    @Override 
    protected void onDestroy() { 
     mediaPlayer.stop(); 

     super.onDestroy(); 
     System.exit(0); 

    } 

    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
     case MENU_SELECT_RESET: 
      this.mainView.gameCount.reset(); 
      Toast.makeText(this, "Has been reset.", Toast.LENGTH_SHORT).show(); 
      return true; 
     case MENU_SELECT_CONTACT: 
      Intent intent = new Intent(Intent.ACTION_SEND); 
      intent.setType("text/plain"); 
      intent.putExtra(Intent.EXTRA_SUBJECT, "idea"); 
      intent.putExtra(Intent.EXTRA_TEXT, "text of email"); 
      intent.putExtra(Intent.EXTRA_EMAIL, 
        new String[] { " [email protected]" }); 
      startActivity(intent); 
     } 
     return false; 
    } 

} 

это мой новый новый activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    tools:context=".MainActivity" > 

    <LinearLayout 
    android:id="@+id/linearLayout1" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 



</LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    <net.canarolab.puzzleroad.MainView 
      android:id="@+id/mainView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 


    </LinearLayout> 

</RelativeLayout> 

но AdMob является dificult для меня .. и не работают. Спасибо

ответ

0

активность:

AdView adview = (AdView) findViewById(R.id.adView1); 
      AdRequest re = new AdRequest(); 
      re.setGender(AdRequest.Gender.FEMALE); 
      adview.loadAd(re); 

Xml:

<View 
     android:id="@+id/under_arrows_" 
     android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:layout_above="@+id/adView1" 
     android:background="#929091"/> 

    <com.google.ads.AdView 
     xmlns:ns="http://schemas.android.com/apk/res/com.adodis.taxmann" 
     android:id="@+id/adView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ns:adSize="BANNER" 
     android:layout_above="@+id/last_update_Dated_text" 
     ns:adUnitId="a14f98f978a08f1"/> 

     <TextView 
      android:id="@+id/last_update_Dated_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentBottom="true" 
      android:background="#000000" 
      android:paddingTop="5dp" 
      android:paddingLeft="5dp" 
      android:paddingBottom="5dp" 
      android:textColor="#ffffff" /> 

Попробуйте это будет работать уверен

0
<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:orientation="vertical" 
    android:layout_width="320" 
    android:layout_height="50" > 

добавив это в AndroidManifest.xml

<activity 
     android:name="com.google.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" > 
    </activity> 
0

1) Определить этот код в файле activity_xml. (Выберите место, где вы хотите показывать ваше объявление)

  <com.google.ads.AdView 

      android:id="@+id/adView" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       ads:adUnitId="a14e2f8fe3af5a6" 
       ads:adSize="SMART_BANNER" 
       ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
       ads:loadAdOnCreate="true"/> 

2) Запишите этот код в MainActivity.java

protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // This will request for new ads. 

     AdView adView = (AdView)this.findViewById(R.id.adView); 
     adView.loadAd(new AdRequest()); 


    } 

3) Определить этот код в manifest.xml

<application> 
    <activity android:name="com.google.ads.AdActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

    </application> 

Примечание: Убедитесь, что имя пакета вашего проекта, определенного вами в AdMob Dashboard я Правильно.

+0

Основная проблема заключается в mainView и adView в том же activity_xml – user2206978

Смежные вопросы