无法将Google广告横幅添加到我的Android Studio项目中。 如果有人可以帮助我,我将非常感谢。我只是不明白我做错了什么。 :/ 我遵循的教程是:https://www.youtube.com/watch?v=w7muIkMYE_A
编辑:现在我稍微更改了代码,并发生了新错误。 Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.codereddev.howtoandroidsoundboard">
...
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths"/>
-->
<meta-data
android:name ="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity
android:name=".SoundboardActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FavoriteActivity" />
<!-- Necessary for sharing sounds on Android 5.1+ -->
<provider
android:authorities="${applicationId}.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
</provider>
</application>
</manifest>
我的SoundboardActivity类没有更改:
public class SoundboardActivity
extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<ArrayList<SoundObject>> {
AdView mAdview;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soundboard);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdview = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
mAdview.loadAd(adRequest);
...
新错误为:
03-24 21:28:53.943 24135-24135/de.codereddev.howtoandroidsoundboard
E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.codereddev.howtoandroidsoundboard, PID: 24135
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data
at android.app.ActivityThread.installProvider(ActivityThread.java:6396)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data
at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:608)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)
at android.support.v4.content.FileProvider.attachInfo(FileProvider.java:392)
at android.app.ActivityThread.installProvider(ActivityThread.java:6391)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
答案 0 :(得分:1)
也许是清单文件中的问题。
尝试以下类型的清单。
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- 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-3940256099942544~3347511713"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 1 :(得分:1)
更新您的AndroidManifest.xml
通过添加名称为com.google.android.gms.ads.APPLICATION_ID的代码,将AdMob应用ID添加到应用的AndroidManifest.xml文件中,如下所示。
您可以在AdMob用户界面中找到您的应用ID。对于android:value,请在引号中插入您自己的AdMob应用ID,如下所示。
<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>
</manifest>