首先,几天前有些广告有效,但是今天我注意到它们停止了工作,我不知道我是否更改了某些内容。

他们无法在任何设备上使用,并且我不使用测试广告

在Android Studio的测试设备中,他们在顶部显示“测试广告”的小文本(即使用我的admob ID,所以这不是问题),但是当我制作APK并在设备上运行它时,广告却没有出现,甚至根本没有测试,它们就消失了,让我告诉你我的意思:

在测试虚拟设备中:https://gyazo.com/704e18c00544794ec4e29faad1a1ab8d

在实际设备中:https://imgur.com/a/iERofay

我会在这里放一些代码,但是我不知道我应该在这里放什么代码,所以我让你们告诉我要发送什么,以便你们看到问题所在。

与广告有关的所有文件都在gif中:
https://gyazo.com/8ca6c2b10e9b392c424f641ffaefb26a

(告诉我您要我发送什么文件,我将在这里发送)

(对不起,英语不好,我来自西班牙)

我用////////审查了广告ID和应用ID!

清单活动

package com.example.samplestickerapp;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;


public class StickerPackListActivity extends AddStickerPackActivity {
    private PublisherAdView mPublisherAdView;
    private InterstitialAd mInterstitialAd;
    public static final String EXTRA_STICKER_PACK_LIST_DATA = "sticker_pack_list";
    private static final int STICKER_PREVIEW_DISPLAY_LIMIT = 5;
    private LinearLayoutManager packLayoutManager;
    private RecyclerView packRecyclerView;
    private StickerPackListAdapter allStickerPacksListAdapter;
    private WhiteListCheckAsyncTask whiteListCheckAsyncTask;
    private ArrayList<StickerPack> stickerPackList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sticker_pack_list);
        MobileAds.initialize(this, "ca-app-pub-///////////~/////////");
        mPublisherAdView = findViewById(R.id.publisherAdView);
        PublisherAdRequest adRequest = new PublisherAdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        mPublisherAdView.loadAd(adRequest);
        packRecyclerView = findViewById(R.id.sticker_pack_list);
        stickerPackList = getIntent().getParcelableArrayListExtra(EXTRA_STICKER_PACK_LIST_DATA);
        showStickerPackList(stickerPackList);
    }

    @Override
    protected void onResume() {
        super.onResume();
        whiteListCheckAsyncTask = new WhiteListCheckAsyncTask(this);
        whiteListCheckAsyncTask.execute(stickerPackList.toArray(new StickerPack[stickerPackList.size()]));
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (whiteListCheckAsyncTask != null && !whiteListCheckAsyncTask.isCancelled()) {
            whiteListCheckAsyncTask.cancel(true);
        }
    }

    private void showStickerPackList(List<StickerPack> stickerPackList) {
        allStickerPacksListAdapter = new StickerPackListAdapter(stickerPackList, onAddButtonClickedListener);
        packRecyclerView.setAdapter(allStickerPacksListAdapter);
        packLayoutManager = new LinearLayoutManager(this);
        packLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
                packRecyclerView.getContext(),
                packLayoutManager.getOrientation()
        );
        packRecyclerView.addItemDecoration(dividerItemDecoration);
        packRecyclerView.setLayoutManager(packLayoutManager);
        packRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(this::recalculateColumnCount);
    }


    private final StickerPackListAdapter.OnAddButtonClickedListener onAddButtonClickedListener = pack -> {
        addStickerPackToWhatsApp(pack.identifier, pack.name);
    };

    private void recalculateColumnCount() {
        final int previewSize = getResources().getDimensionPixelSize(R.dimen.sticker_pack_list_item_preview_image_size);
        int firstVisibleItemPosition = packLayoutManager.findFirstVisibleItemPosition();
        StickerPackListItemViewHolder viewHolder = (StickerPackListItemViewHolder) packRecyclerView.findViewHolderForAdapterPosition(firstVisibleItemPosition);
        if (viewHolder != null) {
            final int max = Math.max(viewHolder.imageRowView.getMeasuredWidth() / previewSize, 1);
            int numColumns = Math.min(STICKER_PREVIEW_DISPLAY_LIMIT, max);
            allStickerPacksListAdapter.setMaxNumberOfStickersInARow(numColumns);
        }
    }


    static class WhiteListCheckAsyncTask extends AsyncTask<StickerPack, Void, List<StickerPack>> {
        private final WeakReference<StickerPackListActivity> stickerPackListActivityWeakReference;

        WhiteListCheckAsyncTask(StickerPackListActivity stickerPackListActivity) {
            this.stickerPackListActivityWeakReference = new WeakReference<>(stickerPackListActivity);
        }

        @Override
        protected final List<StickerPack> doInBackground(StickerPack... stickerPackArray) {
            final StickerPackListActivity stickerPackListActivity = stickerPackListActivityWeakReference.get();
            if (stickerPackListActivity == null) {
                return Arrays.asList(stickerPackArray);
            }
            for (StickerPack stickerPack : stickerPackArray) {
                stickerPack.setIsWhitelisted(WhitelistCheck.isWhitelisted(stickerPackListActivity, stickerPack.identifier));
            }
            return Arrays.asList(stickerPackArray);
        }

        @Override
        protected void onPostExecute(List<StickerPack> stickerPackList) {
            final StickerPackListActivity stickerPackListActivity = stickerPackListActivityWeakReference.get();
            if (stickerPackListActivity != null) {
                stickerPackListActivity.allStickerPacksListAdapter.setStickerPackList(stickerPackList);
                stickerPackListActivity.allStickerPacksListAdapter.notifyDataSetChanged();
            }
        }
    }
}


Android清单

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.samplestickerapp">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="false"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:name=".StickerApplication"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name=".EntryActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".StickerPackListActivity"
            android:label="@string/title_activity_sticker_packs_list" />
        <activity
            android:name=".StickerPackDetailsActivity"
            android:parentActivityName=".StickerPackListActivity"
            tools:ignore="UnusedAttribute">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.samplestickerapp.StickerPackListActivity" />
        </activity>
        <activity
            android:name=".StickerPackInfoActivity"
            android:label="@string/title_activity_sticker_pack_info"
            android:parentActivityName=".StickerPackDetailsActivity"
            tools:ignore="UnusedAttribute">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.samplestickerapp.StickerPackDetailsActivity" />
        </activity>

        <provider
            android:name=".StickerContentProvider"
            android:authorities="${contentProviderAuthority}"
            android:enabled="true"
            android:exported="true"
            android:readPermission="com.whatsapp.sticker.READ" />
                <meta-data
                    android:name="com.google.android.gms.ads.AD_MANAGER_APP"
                    android:value="true"/>
        <meta-data
            android:name="com.google.android.gms.ads.ca-app-pub-/////////////~//////////"
            android:value="ca-app-pub-/////////////~//////////"/>
    </application>
</manifest>

最佳答案

创建admob帐户并添加应用后,您将获得清单和初始化广告中使用的应用ID。

现在,您需要从adMob帐户中为添加项创建添加单元,并将您的添加单元ID与您要在设备中显示的addView链接起来。

如果您使用了网站上的默认代码,则您可能正在使用ID作为测试广告单元。您需要将其替换为广告单元ID。

发布应用后,您需要将Google Play上的应用与adMob帐户关联。

最后,添加项仅在可以连接互联网时显示。

根据评论编辑

 <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
     android:value = "your-application-id-goes-here"/>



Make sure you have updated AdMob with your payment details
Make sure that the ads you created in AdMob are banner ads.
Check your AdMob dashboard to see the status of your ads, are they active?
Verify you used the correct Ad Unit Id.
Give it 24 hours, it can take time for an ad to become active in your region



请尝试遵循以下准则here

检查代码中的以下几行

    PublisherAdRequest adRequest = new PublisherAdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
    mPublisherAdView.loadAd(adRequest);


代替使用
    ((AdView)findViewById(R.id.adView))。loadAd(new AdRequest.Builder()。build());

08-18 17:42
查看更多