I want to show ads in a service. google admob works well because it needs context, but some other ad services like unity ads, adcolony, appodeal need activity context.
How can I provide activity context in a service. I think create an Activity will works but ads need some time to load the ad and then show so create a blank activity and show it.
For unity:
UnityAds.initialize(this, "xxxxxxx", new IUnityAdsListener() {
@Override
public void onUnityAdsReady(String s) {
Timber.e("onUnityAdsReady");
}
@Override
public void onUnityAdsStart(String s) {
Timber.e("onUnityAdsStart");
}
@Override
public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
Timber.e("onUnityAdsFinish");
}
@Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
Timber.e("onUnityAdsError");
}
});
For adclony:
AdColony.configure(this, "xxxx", "xxx");
adColonyInterstitialListener = new AdColonyInterstitialListener() {
@Override
public void onRequestFilled(AdColonyInterstitial ad) {
adColonyInterstitial = ad;
/** Store and use this ad object to show your ad when appropriate */
}
};
AdColony.requestInterstitial("xxx", adColonyInterstitialListener);
I want to show these ads from service how can I do it while they need activity context.