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

时间:2020-08-12 19:08:55

标签: java android-studio admob ads

我在Android Studio上制作的应用程序中实施奖励广告(使用AdMob)时遇到了一些麻烦。 当我放置测试应用程序ID和测试广告单元时,它可以完美运行并显示测试广告,但是当我尝试放置自己的应用程序ID和广告单元时,广告将不再加载。

我创建了admob帐户后等待了一个多星期,所以对我而言,问题与此无关。

我在想你是否可以帮助我。

AndroidManifest.xml:

 <?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

谢谢您的帮助。

Krisix

1 个答案:

答案 0 :(得分:0)

  1. 检查您的Admob帐户,我遇到了类似的问题,但事实证明我的帐户有问题。 (如果展示测试广告,则可能不是代码问题。)

  2. 尝试添加此代码:

     @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
     ...