I have been trying to implement ads for which I have chosen to use leadbolt service but when I try to load ads it gives me error" Ad failed to load - activity not defined", I tried my best to find out where it needs to be defined but I couldn't. Please help me out this time and I know that startsession is deprecated. Here is my activity
public class TopRatedFragment extends Fragment {
private ProgressBar progress;
private WebView myWebView2;
private Menu optionsMenu;
private static final String APP_API_KEY = "xxxxxxxxxxx";
private static final String LOCATION_CODE = "inapp";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);
String url = "http://example.com";
myWebView2 = (WebView) rootView.findViewById(R.id.webViewTop);
myWebView2.setWebChromeClient(new myWebViewClient());
myWebView2.getSettings().setJavaScriptEnabled(true);
progress = (ProgressBar) rootView.findViewById(R.id.progressBar3);
progress.setMax(100);
setHasOptionsMenu(true);
if(savedInstanceState == null) {
AppTracker.setModuleListener(leadboltListener);
// Initialize Leadbolt SDK
//deprecated
AppTracker.startSession(getActivity(), APP_API_KEY);
myWebView2.loadUrl(url);
}
myWebView2.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView View, String url) {
View.loadUrl(url);
TopRatedFragment.this.progress.setProgress(0);
return true;
}
});
myWebView2.setOnKeyListener(new android.view.View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
WebView webView = (WebView) v;
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
webView.goBack();
return true;
}
break;
}
}
return false;
}
});
return rootView;
}
public AppModuleListener leadboltListener = new AppModuleListener() {
@Override
public void onModuleCached(final String placement) {
Toast.makeText(getActivity(), "Ad successfully cached - " + placement, Toast.LENGTH_SHORT).show();
// Ad has been cached, now enable the Show Ad button
}
@Override
public void onModuleClicked(String placement) {
Toast.makeText(getActivity(), "Ad clicked", Toast.LENGTH_SHORT).show();
}
@Override
public void onModuleClosed(String placement) {
Toast.makeText(getActivity(), "Ad closed", Toast.LENGTH_SHORT).show();
}
@Override
public void onModuleFailed(String placement, String error, boolean isCache) {
if(isCache) {
Toast.makeText(getActivity(), "Ad failed to cache - "+error, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Ad failed to load - "+error, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onModuleLoaded(String placement) {
Toast.makeText(getActivity(), "Ad displayed", Toast.LENGTH_SHORT).show();
// Ad has been shown, now disable to the Show Ad button
}
@Override
public void onMediaFinished(boolean viewCompleted) {}
};
private class myWebViewClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progress.setProgress(newProgress);
//loadingTitle.setProgress(newProgress);
// hide the progress bar if the loading is complete
if (newProgress == 100) {
progress.setVisibility(View.GONE);
setRefreshActionButtonState(false);
// here i try to display ads.
AppTracker.loadModule(getActivity(), LOCATION_CODE);
} else{
progress.setVisibility(View.VISIBLE);
}
}
}}
Thanks for your time.
Did you know that that you can generate cash by locking special areas of your blog or website?
RépondreSupprimerSimply join AdWorkMedia and embed their content locking plugin.