Use LeadBolt to show ads in an Android WebView
If you’re looking for a way to show ads in your Android app without including any ad network SDKs, read on. I just created a video tutorial showing how to get set up with LeadBolt ads in an Android WebView without using their SDK at all.
If you missed my previous review of LeadBolt, take a look now. I’ve seen an eCPM of $3.42 so far this month with standard banners, so I’m still pleased with the performance of LeadBolt.
Then watch this video to see how you can get set up in just a few minutes.
Don’t forget to click like if you found the video helpful! You can download the source code for this project, or look below for a quick summary.
Note that you’ll need to sign up for LeadBolt to see the ads yourself, as no ads will display without a valid ID. The signup process is pretty painless, though.
Code changes
Set up the webview in the layout
<WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />
Set up the WebView in the activity, in onCreate
// NOTE you MUST put a real ID in place of 'your_ad_id_here' // or you will not see an ad! WebView wv = (WebView) findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.setBackgroundColor(Color.TRANSPARENT); String html = "<html><body style='margin:0;padding:0;'><script type='text/javascript' src='https://ad.leadboltads.net/show_app_ad.js?section_id=your_ad_id_here'></script></body></html>"; wv.loadData(html, "text/html", "utf-8");
Set up the permissions in the manifest
<uses-permission android:name="android.permission.INTERNET"/>
It’s that easy!
That’s it! You can now deploy your app with ads without adding any SDK!
If you haven’t signed up for LeadBolt yet, sign up now. Then grab the project or just copy the code above, and your Android app is set up to show ads in a WebView!
