AdMob横幅广告在资产文件夹的HTML文件中

huangapple go评论83阅读模式
英文:

AdMob banner ads in assets folder HTML files

问题

以下是翻译好的部分:

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private Context mContext;

    ArrayList<String> titleArrayList;
    private RecyclerView mRecyclerView;
    AdView mAdView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // 当广告加载完成时执行的代码。
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                // 当广告请求失败时执行的代码。
            }

            @Override
            public void onAdOpened() {
                // 当广告打开覆盖屏幕时执行的代码。
            }

            @Override
            public void onAdClicked() {
                // 当用户点击广告时执行的代码。
            }

            @Override
            public void onAdLeftApplication() {
                // 当用户离开应用程序时执行的代码。
            }

            @Override
            public void onAdClosed() {
                // 当用户在点击广告后返回应用程序时执行的代码。
            }
        });

        mContext = MainActivity.this;

        titleArrayList = new ArrayList<String>();
        titleArrayList.add(Constants.Title_1);
        titleArrayList.add(Constants.Title_2);
        titleArrayList.add(Constants.Title_3);
        titleArrayList.add(Constants.Title_4);
        titleArrayList.add(Constants.Title_5);

        mRecyclerView = (RecyclerView) findViewById(R.id.title_layout_RecyclerView);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        TitleAdapter adapter = new TitleAdapter(mContext, titleArrayList, new CustomItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Intent desIntent = new Intent(mContext, DescriptionActivity.class);
                desIntent.putExtra("titles", titleArrayList.get(position));
                startActivity(desIntent);
                Toast.makeText(mContext, "clicked" + titleArrayList.get(position), Toast.LENGTH_SHORT).show();
            }
        });

        mRecyclerView.setAdapter(adapter);
    }
}
英文:

Is it possible to add AdMob banner ads to the assets folder HTML files?
I have made a Ebook using a recyclerview for the list and assets folder containing HTML files containing the content of the relevant title. I have added a AdMob banner to Activity_Main where the list of titles are present. And now want to add a similar banner ads to the content in the assets folder.

PS
This is the first app I build, learning through Youtube and other sites like Stackoverflow

public class MainActivity extends AppCompatActivity {

private static final String TAG = &quot;MainActivity&quot;;
private Context mContext;
ArrayList&lt;String&gt; titleArrayList;
private RecyclerView mRecyclerView;
AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the user is about to return
// to the app after tapping on an ad.
}
});
mContext = MainActivity.this;
titleArrayList = new ArrayList&lt;String&gt;();
titleArrayList.add(Constants.Title_1);
titleArrayList.add(Constants.Title_2);
titleArrayList.add(Constants.Title_3);
titleArrayList.add(Constants.Title_4);
titleArrayList.add(Constants.Title_5);
mRecyclerView = (RecyclerView) findViewById(R.id.title_layout_RecyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
TitleAdapter adapter = new TitleAdapter(mContext, titleArrayList, new CustomItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Intent desIntent = new Intent(mContext,DescriptionActivity.class);
desIntent.putExtra(&quot;titles&quot;,titleArrayList.get(position));
startActivity(desIntent);
Toast.makeText(mContext, &quot;clicked&quot;+titleArrayList.get(position), Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.setAdapter(adapter);
}

}

答案1

得分: 1

AdMob SDK 严格仅支持本地应用。对于在“html”或网站上展示广告,您需要通过 AdSense 进行操作。

您需要在 AdSense 中提交您的网站 URL 来发出请求。

总之,使用 AdMob SDK 无法实现这一点,最好在底部使用横幅广告。或者,当用户在不同的 html 页面之间切换或经过一定时间后,可以考虑放置插页式广告。

英文:

AdMob SDK is strictly native only. For ads on 'html' or websites, you'd have to do it via AdSense.

For this you would have to raise a request in AdSense by submitting your website URL.

Bottom line, you can't do this with AdMob SDK and you're better off with a banner ad at the bottom. Or you can maybe place an interstitial ad when your user is switching between different html pages or after a certain amount of time.

huangapple
  • 本文由 发表于 2020年5月30日 01:02:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/62091120.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定