広告バナーを表示/非表示にするプラグインを実装できます。あなたができるようになりまし
<plugin name="com.example.AdBanner" value="com.example.AdBannerPlugin"/>
:
com.example.AdBanner:あなたのメインの活動で
public class AdBannerPlugin extends Plugin {
public static final String BROADCAST_ACTION_SHOW_AD_BANNER = "com.example.SHOW_AD_BANNER";
public static final String BROADCAST_ACTION_HIDE_AD_BANNER = "com.example.HIDE_AD_BANNER";
private static final String ACTION_SHOW_AD_BANNER = "showBanner";
private static final String ACTION_HIDE_AD_BANNER = "hideBanner";
/**
* @see Plugin#execute(String, org.json.JSONArray, String)
*/
@Override
public PluginResult execute(final String action, final JSONArray data, final String callbackId) {
if (ACTION_SHOW_AD_BANNER.equals(action)) {
final Intent intent = new Intent();
intent.setAction(BROADCAST_ACTION_SHOW_AD_BANNER);
this.ctx.getApplicationContext().sendBroadcast(intent);
return new PluginResult(OK);
} else if (ACTION_HIDE_AD_BANNER.equals(action)) {
final Intent intent = new Intent();
intent.setAction(BROADCAST_ACTION_HIDE_AD_BANNER);
this.ctx.getApplicationContext().sendBroadcast(intent);
return new PluginResult(OK);
} else {
Log.e(LOG_TAG, "Unsupported action: " + action);
return new PluginResult(INVALID_ACTION);
}
}
}
:
plugins.xmlで
private BroadcastReceiver adReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
if (BROADCAST_ACTION_SHOW_AD_BANNER.equals(intent.getAction())) {
//check if the ad view is not visible and show it
} else if (BROADCAST_ACTION_HIDE_AD_BANNER.equals(intent.getAction())) {
//check if the ad view is visible and hide it
}
}
};
@Override
public void onResume() {
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BROADCAST_ACTION_HIDE_AD_BANNER);
intentFilter.addAction(BROADCAST_ACTION_SHOW_AD_BANNER);
registerReceiver(adReceiver, intentFilter);
super.onResume();
}
@Override
public void onPause() {
unregisterReceiver(adReceiver);
super.onPause();
}
ここ は一例ですjavascriptから広告バナーを非表示にする:
cordova.exec(onSuccess, onFail, 'com.example.AdBanner', 'hideBanner', []);