我刚接触安卓应用程序开发。我正在准备一个应用程序,应该在底部显示Admob广告,为此我在Admob上创建了一个帐户并获取了发布者ID,并将其放置在我的代码中。
但客户给了我以下集成详细信息:
广告单元ID -
xxxx(五位数)
这是应用程序ID:
0axxxxxb-xxdx-xxxa-xxxx-cxxbxxxxxaxx(这里的x是数字)
我的问题是,广告单元ID和发布者ID是否相同?如果是这样,我的发布者ID有15个数字,但广告单元ID只有5个数字,现在我该怎么办?
我刚接触安卓应用程序开发。我正在准备一个应用程序,应该在底部显示Admob广告,为此我在Admob上创建了一个帐户并获取了发布者ID,并将其放置在我的代码中。
但客户给了我以下集成详细信息:
广告单元ID -
xxxx(五位数)
这是应用程序ID:
0axxxxxb-xxdx-xxxa-xxxx-cxxbxxxxxaxx(这里的x是数字)
我的问题是,广告单元ID和发布者ID是否相同?如果是这样,我的发布者ID有15个数字,但广告单元ID只有5个数字,现在我该怎么办?
根据Admob官方文档,我认为这是相同的事情。
添加一个广告横幅只需五行代码:
- 导入com.google.ads.*
- 声明AdView实例
- 创建AdView并指定单元ID——即您的AdMob发布商ID
- 将视图添加到UI中
- 通过广告加载它
请与您的客户进一步沟通。
我使用这个方法从我的应用程序的onCreate()
方法运行中获取adUnitId
。
public void getIdThread() {
new Thread(new Runnable() {
@Override
public void run() {
// Do not call this function from the main thread. Otherwise,
// an IllegalStateException will be thrown.
Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
Log.d("AD_INFO", "adInfo :: " +adInfo);
} catch (IOException e) {
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (GooglePlayServicesNotAvailableException e) {
// Google Play services is not available entirely.
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final String adUnitId = adInfo.getId();
final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
Log.d("AD_INFO", "adUnitId :: " +adUnitId);
Log.d("AD_INFO", "isLAT :: " +isLAT);
}
}).start();
}
这是一个 adUnitId
的格式:
da123eb7-19a9-43aa-a98b-9ae24de45f25
不,PublisherId 是唯一的账号ID,而ad Unit id是每个应用程序的ID。