本文介绍了如何以编程方式设置 Admob appID (19.1.0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
19.1.0 版之前,可以像这样以编程方式设置 appID:
Before version 19.1.0, the appID could be set programmatically like this:
MobileAds.initialize (Context context, String appID)
新方法是
initialize(Context, OnInitializationCompleteListener)
在内部,该方法将 null
作为 appID 传递:
Internally, that method passes null
as appID:
public static void initialize(Context var0, OnInitializationCompleteListener var1) {
zzxw.zzqq().zza(var0, (String)null, var1);
}
这是否意味着不应再以编程方式设置 appID?
Does this mean that appID should no longer be set programmatically?
推荐答案
您必须将 APPLICATION_ID 放在清单文件中,您可以在 AdMob UI 中找到您的 App ID.对于 android:value,请在引号中插入您自己的 AdMob 应用 ID,如下所示.
You have to put APPLICATION_ID on manifest file , you can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
之后,您可以以编程方式对其进行更改
after that you can change it programmatically
try {
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
String myApiKey = bundle.getString("com.google.android.gms.ads.APPLICATION_ID");
Log.d(TAG, "Name Found: " + myApiKey);
ai.metaData.putString("com.google.android.gms.ads.APPLICATION_ID", "ca-app-pub-3940256099942544~3347511713");//you can replace your key APPLICATION_ID here
String ApiKey = bundle.getString("com.google.android.gms.ads.APPLICATION_ID");
Log.d(TAG, "ReNamed Found: " + ApiKey);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage());
} catch (NullPointerException e) {
Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage());
}
这篇关于如何以编程方式设置 Admob appID (19.1.0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!