java 奖励测试广告显示,但不是真实的的

b5lpy0ml  于 2023-01-15  发布在  Java
关注(0)|答案(2)|浏览(123)

我在Android Studio上制作的应用程序中实现奖励广告(使用AdMob)时遇到了一些问题。当我输入测试应用程序ID和测试广告单元时,它工作正常,测试广告出现,但当我尝试输入自己的应用程序ID和广告单元时,广告不再加载。
我等了一个多星期后,创建我的admob帐户,所以对我来说,问题是无关的。
我在想你能不能帮我。
安卓清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="(hide)">
    <!-- Internet Permission -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        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-1726769558644129~3661017334" />

        <activity
            android:name=".SpashScreenActivity"
            android:theme="@style/SplashScreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".LoginActivity" />
        <activity android:name=".DashboardActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <activity android:name=".Main" />
        
    </application>

</manifest>

HomeFragment.java :

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment implements RewardedVideoAdListener{

    public HomeFragment() {
        // Required empty public constructor
    }

  

    //init view
    ImageButton addCoinsBtn;
    
    
    //AdRewarded
    private RewardedVideoAd mAd;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =inflater.inflate(R.layout.fragment_home, container, false);

        MobileAds.initialize(getActivity(), "ca-app-pub-1726769558644129~3661017334");

              
        // Use an activity context to get the rewarded video instance
        mAd = MobileAds.getRewardedVideoAdInstance(getActivity());
        mAd.setRewardedVideoAdListener(this);
        loadRewardedVideoAd();


        addCoinsBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(mAd.isLoaded())
                {
                    mAd.show();
                    addCoinsBtn.setVisibility(View.INVISIBLE);
                    waitAdLL.setVisibility(View.VISIBLE);
                }

            }

        });

        

        return view;

    }

    private void loadRewardedVideoAd() {
        mAd.loadAd("ca-app-pub-1726769558644129/3118091850", new AdRequest.Builder().build());
    }

    // Required to reward the user.
    @Override
    public void onRewarded(RewardItem reward) {

        // Reward the user.

       
    }

    // The following listener methods are optional.
    @Override
    public void onRewardedVideoAdLeftApplication() {
        Toast.makeText(getActivity(), "onRewardedVideoAdLeftApplication",Toast.LENGTH_SHORT).show();

    }


    @Override
    public void onRewardedVideoAdClosed() {
        //Toast.makeText(getActivity(), "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
        loadRewardedVideoAd();
    }

    @Override
    public void onRewardedVideoAdOpened() {
        //Toast.makeText(getActivity(), "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoStarted() {
        //Toast.makeText(getActivity(), "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int errorCode) {
        Toast.makeText(getActivity(), "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
        loadRewardedVideoAd();
    }

    @Override
    public void onRewardedVideoCompleted() {

    }

    @Override
    public void onResume() {
        mAd.resume(getActivity());
        super.onResume();
    }
    @Override
    public void onPause() {
        mAd.pause(getActivity());
        super.onPause();
    }
    @Override
    public void onDestroy() {
        mAd.destroy(getActivity());
        super.onDestroy();
    }


    @Override
    public void onRewardedVideoAdLoaded() {       
        //Toast.makeText(getActivity(), "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
    }


}

My Admob information
谢谢你的帮助。
克里希斯

3j86kqsm

3j86kqsm1#

1.检查您的Admob帐户,我有一个类似的问题,但原来是我的帐户有问题。(如果测试广告显示,这可能不是代码问题。
1.尝试添加此代码:

@Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                      Bundle savedInstanceState) {
 // Inflate the layout for this fragment
 View view =inflater.inflate(R.layout.fragment_home, container, false);

MobileAds.initialize(this, new OnInitializationCompleteListener() {
 @Override
 public void onInitializationComplete(InitializationStatus initializationStatus) {}
});

// Use an activity context to get the rewarded video instance
 mAd = MobileAds.getRewardedVideoAdInstance(getActivity());
 mAd.setRewardedVideoAdListener(this);
 loadRewardedVideoAd();

// Your code
 ...
wn9m85ua

wn9m85ua2#

有两种类型的广告称为奖励广告和奖励插播广告。请尝试生成另一个广告单元并添加相关的广告单元凭据。

相关问题