我正在从事这项活动 请告诉我 在将用户重定向到Google Play商店之前,如何显示插页式广告?
有可能吗?
public class MyClinet extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("myhostsite")) {
return false;
}
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Google Play app is not installed, you may want to open the app store link
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}
}
答案 0 :(得分:0)
只需遵循此官方Google教程,您就可以实现自己想要的https://developers.google.com/admob/android/interstitial
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
但是,核心是在插页式广告中添加一个侦听器,并在广告关闭时重定向用户。像这样:
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Your redirect code goes here
}
});