facebook twitter hatena line google mixi email

「Android/広告組込/google/admanager/バナー」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==公式== https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner?hl=ja ==レイアウト== main_activity.xml <pre> <RelativeLayout xmlns:android="http:/...」)
 
(レイアウト)
行33: 行33:
  
 
</RelativeLayout>
 
</RelativeLayout>
 +
</pre>
 +
 +
==サイズ設定とunitId設定==
 +
<pre>
 +
PublisherAdView adView = new PublisherAdView(this);
 +
adView.setAdSizes(AdSize.BANNER);
 +
adView.setAdUnitId("/6499/example/banner");
 +
</pre>
 +
 +
==ロード処理==
 +
<pre>
 +
import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
 +
import com.google.android.gms.ads.doubleclick.PublisherAdView;
 +
 +
public class MainActivity extends AppCompatActivity {
 +
    private PublisherAdView mPublisherAdView;
 +
 +
    protected void onCreate(Bundle savedInstanceState) {
 +
        super.onCreate(savedInstanceState);
 +
        setContentView(R.layout.activity_main);
 +
        mPublisherAdView = findViewById(R.id.publisherAdView);
 +
        PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
 +
        mPublisherAdView.loadAd(adRequest);
 +
    }
 +
}
 
</pre>
 
</pre>

2019年10月2日 (水) 19:10時点における版

公式

https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner?hl=ja

レイアウト

main_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">


        <TextView android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <com.google.android.gms.ads.doubleclick.PublisherAdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/publisherAdView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="/6499/example/banner">
        </com.google.android.gms.ads.doubleclick.PublisherAdView>

</RelativeLayout>

サイズ設定とunitId設定

PublisherAdView adView = new PublisherAdView(this);
adView.setAdSizes(AdSize.BANNER);
adView.setAdUnitId("/6499/example/banner");

ロード処理

import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdView;

public class MainActivity extends AppCompatActivity {
    private PublisherAdView mPublisherAdView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPublisherAdView = findViewById(R.id.publisherAdView);
        PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
        mPublisherAdView.loadAd(adRequest);
    }
}