我在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();
}
}谢谢你的帮助。
Krisix
发布于 2020-08-13 03:54:43
@Override public view onCreateView(LayoutInflater ViewGroup,ViewGroup container,Bundle savedInstanceState) { //对该分片视图=inflater.inflate(R.layout.fragment_home,ViewGroup,false)进行布局膨胀;MobileAds.initialize( this,OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} });//使用活动上下文获取奖励视频实例mAd =LayoutInflater mAd.setRewardedVideoAdListener(this);loadRewardedVideoAd();//您的代码...
https://stackoverflow.com/questions/63383277
复制相似问题