如何在Android上添加admobs

时间:2016-06-02 12:15:40

标签: android admob

请协助一些事情,我正在尝试在应用程序上添加admobs,但是当我运行它时它不会在应用程序上显示,但它出现在android工作室预览中。我该如何解决这个问题?

此代码位于主要活动布局

Button

此代码位于问题活动类 -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relatively"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#d15400"
    android:orientation="vertical"
    android:weightSum="1" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.90"
        android:orientation="vertical"
        android:weightSum="1" >

        <LinearLayout
            android:id="@+id/linearLayout11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:orientation="vertical"
            android:weightSum="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/score"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:layout_marginRight="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Score : 1"
                    android:textColor="#ffffff"
                    android:textSize="25.0sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/timers"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:layout_marginRight="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="00:00:49"
                    android:textColor="#ffffff"
                    android:textSize="25.0sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.60"
            android:orientation="vertical"
            android:weightSum="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.40" >

                <TextView
                    android:id="@+id/txtQuestion"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:text="15*2*1-1"
                    android:textColor="#ffffff"
                    android:textSize="35.0sp"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.20"
                android:orientation="vertical"
                android:weightSum="1" >

                <Button
                    android:id="@+id/button1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="80dp"
                    android:layout_marginRight="80dp"
                    android:layout_marginTop="5dp"
                    android:background="#fff"
                    android:gravity="center"
                    android:text="30"
                    android:textColor="#000000"
                    android:textSize="25.0sp" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="80dp"
                    android:layout_marginRight="80dp"
                    android:layout_marginTop="5dp"
                    android:background="#fff"
                    android:gravity="center"
                    android:text="29"
                    android:textColor="#000000"
                    android:textSize="25.0sp" />

                <Button
                    android:id="@+id/button3"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="80dp"
                    android:layout_marginRight="80dp"
                    android:layout_marginTop="5dp"
                    android:background="#fff"
                    android:gravity="center"
                    android:text="32"
                    android:textColor="#000000"
                    android:textSize="25.0sp" />





            </LinearLayout>


        </LinearLayout>



</LinearLayout>
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>


</LinearLayout>

这是清单上的cose

setContentView(R.layout.activity_main);
        AdView adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();
        adView.loadAd(adRequest);

这是资源

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="hitesh.asimplegame">

    <!-- Include required permissions for Google Mobile Ads to run. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".QuestionActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity><![CDATA[
       android:name=".ResultActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" />
        ]]>
        <activity android:name=".Finish" />
        <activity android:name=".SplashScrean" />
        <!-- This meta-data tag is required to use Google Play Services. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <!-- Include the AdActivity configChanges and theme. -->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" />

    </application>

</manifest>

3 个答案:

答案 0 :(得分:1)

您的广告ID应以ca-app-pub-your_key开头 ids,横幅ID和插页符号

所以使用这些:

<string name="banner_ad_unit_id">ca-app-pub-4526809957646802/687614978</string>
<string name="interstitial_ad_unit_id">ca-app-pub-4526809957646802/6876146978</string>

答案 1 :(得分:0)

代码没有问题。问题是,您可能会在几分钟前创建该广告单元ID。因此,它需要更多时间才能出现在真实设备中。如果您确实想知道代码是否有效,请将横幅ID设置为ca-app-pub-3940256099942544/6300978111。这是一个预览ID,它将适合您。

答案 2 :(得分:0)

elif [[ $text2 == 'LANDING' && $text4 == @(FAIL|) ]]; then