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

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

AdMob banner ads in assets folder HTML files

问题

以下是翻译好的部分:

  1. public class MainActivity extends AppCompatActivity {
  2. private static final String TAG = "MainActivity";
  3. private Context mContext;
  4. ArrayList<String> titleArrayList;
  5. private RecyclerView mRecyclerView;
  6. AdView mAdView;
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11. MobileAds.initialize(this, new OnInitializationCompleteListener() {
  12. @Override
  13. public void onInitializationComplete(InitializationStatus initializationStatus) {
  14. }
  15. });
  16. mAdView = findViewById(R.id.adView);
  17. AdRequest adRequest = new AdRequest.Builder().build();
  18. mAdView.loadAd(adRequest);
  19. mAdView.setAdListener(new AdListener() {
  20. @Override
  21. public void onAdLoaded() {
  22. // 当广告加载完成时执行的代码。
  23. }
  24. @Override
  25. public void onAdFailedToLoad(int errorCode) {
  26. // 当广告请求失败时执行的代码。
  27. }
  28. @Override
  29. public void onAdOpened() {
  30. // 当广告打开覆盖屏幕时执行的代码。
  31. }
  32. @Override
  33. public void onAdClicked() {
  34. // 当用户点击广告时执行的代码。
  35. }
  36. @Override
  37. public void onAdLeftApplication() {
  38. // 当用户离开应用程序时执行的代码。
  39. }
  40. @Override
  41. public void onAdClosed() {
  42. // 当用户在点击广告后返回应用程序时执行的代码。
  43. }
  44. });
  45. mContext = MainActivity.this;
  46. titleArrayList = new ArrayList<String>();
  47. titleArrayList.add(Constants.Title_1);
  48. titleArrayList.add(Constants.Title_2);
  49. titleArrayList.add(Constants.Title_3);
  50. titleArrayList.add(Constants.Title_4);
  51. titleArrayList.add(Constants.Title_5);
  52. mRecyclerView = (RecyclerView) findViewById(R.id.title_layout_RecyclerView);
  53. mRecyclerView.setHasFixedSize(true);
  54. mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
  55. TitleAdapter adapter = new TitleAdapter(mContext, titleArrayList, new CustomItemClickListener() {
  56. @Override
  57. public void onItemClick(View v, int position) {
  58. Intent desIntent = new Intent(mContext, DescriptionActivity.class);
  59. desIntent.putExtra("titles", titleArrayList.get(position));
  60. startActivity(desIntent);
  61. Toast.makeText(mContext, "clicked" + titleArrayList.get(position), Toast.LENGTH_SHORT).show();
  62. }
  63. });
  64. mRecyclerView.setAdapter(adapter);
  65. }
  66. }
英文:

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 {

  1. private static final String TAG = &quot;MainActivity&quot;;
  2. private Context mContext;
  3. ArrayList&lt;String&gt; titleArrayList;
  4. private RecyclerView mRecyclerView;
  5. AdView mAdView;
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.activity_main);
  10. MobileAds.initialize(this, new OnInitializationCompleteListener() {
  11. @Override
  12. public void onInitializationComplete(InitializationStatus initializationStatus) {
  13. }
  14. });
  15. mAdView = findViewById(R.id.adView);
  16. AdRequest adRequest = new AdRequest.Builder().build();
  17. mAdView.loadAd(adRequest);
  18. mAdView.setAdListener(new AdListener() {
  19. @Override
  20. public void onAdLoaded() {
  21. // Code to be executed when an ad finishes loading.
  22. }
  23. @Override
  24. public void onAdFailedToLoad(int errorCode) {
  25. // Code to be executed when an ad request fails.
  26. }
  27. @Override
  28. public void onAdOpened() {
  29. // Code to be executed when an ad opens an overlay that
  30. // covers the screen.
  31. }
  32. @Override
  33. public void onAdClicked() {
  34. // Code to be executed when the user clicks on an ad.
  35. }
  36. @Override
  37. public void onAdLeftApplication() {
  38. // Code to be executed when the user has left the app.
  39. }
  40. @Override
  41. public void onAdClosed() {
  42. // Code to be executed when the user is about to return
  43. // to the app after tapping on an ad.
  44. }
  45. });
  46. mContext = MainActivity.this;
  47. titleArrayList = new ArrayList&lt;String&gt;();
  48. titleArrayList.add(Constants.Title_1);
  49. titleArrayList.add(Constants.Title_2);
  50. titleArrayList.add(Constants.Title_3);
  51. titleArrayList.add(Constants.Title_4);
  52. titleArrayList.add(Constants.Title_5);
  53. mRecyclerView = (RecyclerView) findViewById(R.id.title_layout_RecyclerView);
  54. mRecyclerView.setHasFixedSize(true);
  55. mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
  56. TitleAdapter adapter = new TitleAdapter(mContext, titleArrayList, new CustomItemClickListener() {
  57. @Override
  58. public void onItemClick(View v, int position) {
  59. Intent desIntent = new Intent(mContext,DescriptionActivity.class);
  60. desIntent.putExtra(&quot;titles&quot;,titleArrayList.get(position));
  61. startActivity(desIntent);
  62. Toast.makeText(mContext, &quot;clicked&quot;+titleArrayList.get(position), Toast.LENGTH_SHORT).show();
  63. }
  64. });
  65. mRecyclerView.setAdapter(adapter);
  66. }

}

答案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:

确定