I have started integrating Airpushes banner ad "AdView" into my application and have it working well, however I know want to be able to disable the ads if the user has bought my donation key, I have this already set up and just set if the user has the key via a shared preference.
However when I do the below the ad still displays, in my oncreate I have:
AdView ad = (AdView) findViewById(R.id.guideAdView);
if (AppPreferences.getPrefs().getBoolean("full", false)){
ad.setVisibility(View.GONE);
}
AdCallbackListener adCallbackListener = new AdCallbackListener() {
#Override
public void onSDKIntegrationError(String message) {
// Here you will receive message from SDK if it detects any
// integration issue.
}
public void onSmartWallAdShowing() {
// This will be called by SDK when it’s showing any of the
// SmartWall ad.
}
#Override
public void onSmartWallAdClosed() {
// This will be called by SDK when the SmartWall ad is closed.
}
#Override
public void onAdError(String message) {
// This will get called if any error occurred during ad serving.
}
#Override
public void onAdCached(AdType arg0) {
// This will get called when an ad is cached.
}
#Override
public void onVideoAdFinished() {
// TODO Auto-generated method stub
}
#Override
public void onVideoAdShowing() {
// TODO Auto-generated method stub
}
};
if (airPlay == null)
airPlay = new AirPlay(this, adCallbackListener, false);
I know the if (AppPreferences.getPrefs().getBoolean("full", false)) works fine because this is used else where in the activity to display other information if the user does have the full key.
So the question is why goes the above not work for the adView?
I have never used airpush but why don't you just not run the ad code if the user has a key.
There is no point setting up all of the listeners and the new AirPlay object if the ads are not to be displayed.
e.g:
if (AppPreferences.getPrefs().getBoolean("full", false)){
// Do not show ads
AdView ad = (AdView) findViewById(R.id.guideAdView);
ad.setVisibility(View.GONE);
} else {
// Show Ads
// Set up listener (omitted from this example for clarity)
if (airPlay == null) airPlay = new AirPlay(this, adCallbackListener, false);
}
Related
I'm developing Android app on Android studio using Opencv library and when I try to open my app it opens then right after that it closes and displaying crash message. I'm new on mobile development
Using : OpenCV310, Android Studio 3.0,
public class ScanLicensePlateActivity extends AppCompatActivity {
protected AnylineOcrScanView scanView;
private LicensePlateResultView licensePlateResultView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_anyline_ocr);
String license = getString(R.string.anyline_license_key);
// Get the view from the layout
scanView = (AnylineOcrScanView) findViewById(R.id.scan_view);
// Configure the view (cutout, the camera resolution, etc.) via json
// (can also be done in xml in the layout)
scanView.setConfig(new AnylineViewConfig(this, "license_plate_view_config.json"));
// Copies given traineddata-file to a place where the core can access it.
// This MUST be called for every traineddata file that is used
// (before startScanning() is called).
// The file must be located directly in the assets directory
// (or in tessdata/ but no other folders are allowed)
scanView.copyTrainedData("tessdata/GL-Nummernschild-Mtl7_uml.traineddata",
"8ea050e8f22ba7471df7e18c310430d8");
scanView.copyTrainedData("tessdata/Arial.traineddata", "9a5555eb6ac51c83cbb76d238028c485");
scanView.copyTrainedData("tessdata/Alte.traineddata", "f52e3822cdd5423758ba19ed75b0cc32");
scanView.copyTrainedData("tessdata/deu.traineddata", "2d5190b9b62e28fa6d17b728ca195776");
// Configure the OCR for license plate scanning via a custom script file
// This is how you could add custom scripts optimized by Anyline for your use-case
AnylineOcrConfig anylineOcrConfig = new AnylineOcrConfig();
anylineOcrConfig.setCustomCmdFile("license_plates.ale");
// set the ocr config
scanView.setAnylineOcrConfig(anylineOcrConfig);
// initialize with the license and a listener
scanView.initAnyline(license, new AnylineOcrListener() {
#Override
public void onReport(String identifier, Object value) {
// Called with interesting values, that arise during processing.
// Some possibly reported values:
//
// $brightness - the brightness of the center region of the cutout as a float value
// $confidence - the confidence, an Integer value between 0 and 100
// $thresholdedImage - the current image transformed into black and white
// $sharpness - the detected sharpness value (only reported if minSharpness > 0)
}
#Override
public boolean onTextOutlineDetected(List<PointF> list) {
// Called when the outline of a possible text is detected.
// If false is returned, the outline is drawn automatically.
return false;
}
#Override
public void onResult(AnylineOcrResult result) {
// Called when a valid result is found
String results[] = result.getText().split("-");
String licensePlate = results[1];
licensePlateResultView.setLicensePlate(licensePlate);
licensePlateResultView.setVisibility(View.VISIBLE);
}
#Override
public void onAbortRun(AnylineOcrError code, String message) {
// Is called when no result was found for the current image.
// E.g. if no text was found or the result is not valid.
}
});
// disable the reporting if set to off in preferences
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
SettingsFragment.KEY_PREF_REPORTING_ON, true)) {
// The reporting of results - including the photo of a scanned meter -
// helps us in improving our product, and the customer experience.
// However, if you wish to turn off this reporting feature, you can do it like this:
scanView.setReportingEnabled(false);
}
addLicensePlateResultView();
}
private void addLicensePlateResultView() {
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
licensePlateResultView = new LicensePlateResultView(this);
licensePlateResultView.setVisibility(View.INVISIBLE);
mainLayout.addView(licensePlateResultView, params);
licensePlateResultView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startScanning();
}
});
}
private void startScanning() {
licensePlateResultView.setVisibility(View.INVISIBLE);
// this must be called in onResume, or after a result to start the scanning again
scanView.startScanning();
}
#Override
protected void onResume() {
super.onResume();
startScanning();
}
#Override
protected void onPause() {
super.onPause();
scanView.cancelScanning();
scanView.releaseCameraInBackground();
}
#Override
public void onBackPressed() {
if (licensePlateResultView.getVisibility() == View.VISIBLE) {
startScanning();
} else {
super.onBackPressed();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
}}
source code is here.
If possible please help.
Logcat error shown here
Ideally more information regarding the error would be best i.e the opencv library version etc. Given it seems to be an Android issue, I would advise
File and issue or view issues pertaining to this error on their github page. Search for related Android errors to see if they match.
IF you cannot find a related error, file an issue there.
I am integrating AppLovin sdk to integrate ads in my app.My app is a game app and I want my user to reward coins when they click on the ads.But adclicklistener of AppLovin seems not working in my case.
The Code:
private AppLovinAdView adView;
// Create AppLovin Ad View
final AppLovinSdk sdk = AppLovinSdk.getInstance(SceneActivity.this);
adView = new AppLovinAdView(sdk, AppLovinAdSize.INTERSTITIAL, SceneActivity.this);
//Show ad after 4 levels
if (currentLevel % 4 == 0) {
// An ad is available to display. It's safe to call show.
AppLovinInterstitialAd.show(SceneActivity.this);
adView.loadNextAd();
}
adView.setAdClickListener(new AppLovinAdClickListener() {
#SuppressLint("SimpleDateFormat")
#Override
public void adClicked(AppLovinAd arg0)
{
System.out.println("Adclicked");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String today = sdf.format(new Date());
if (!today.equalsIgnoreCase(getLastDownloadDate())) {
// give coins once per day
modifyMoney(MONEY_DOWNLOAD_GAME);
// put last Download date
setLastDownloadDate(today);
}
}
});
The INTERSTITIAL ad is displaying but the click listener is not working.
The problem is that you are mixing AppLovinInterstitialAd (which internally owns its own instance of AppLovinAdView) and your own standalone AppLovinAdView. When you call AppLovinInterstitialAd.show(), you're bypassing your ad view which had the listener attached to it.
So you don't need to use AppLovinAdView at all... give this a try:
private void showInterstitial() {
final AppLovinSdk sdk = AppLovinSdk.getInstance(mActivity);
final AppLovinInterstitialAdDialog adDialog = AppLovinInterstitialAd.create(sdk, mActivity);
adDialog.setAdClickListener(new AppLovinAdClickListener() {
#Override
public void adClicked(AppLovinAd appLovinAd) {
// Ad clicked, add your on-click logic here
}
});
adDialog.show(); // Display a pre-cached interstitial
}
I am attempting to implement the AdMob with Google Play Services.
So far I have the default test banner appearing but I want to try some of the test ads.
I read that the emulator (AVD) must have Google APIs 16 or 17 as the target in order to test the AdMob however when I create a device that has this as target the emulator fails to load ( i left it for a good 20 minutes still has not loaded yet :( I just see the flashing android logo
This my AVD device
This is my AdFragment class that contains all the code related to the advertisements
public class AdFragment extends Fragment
{
private AdView mAdView;
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_ad, container, false);
}
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
mAdView = (AdView)getView().findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Start loading the ad in the background.
mAdView.loadAd(adRequest);
}
/** Called when leaving the activity */
#Override
public void onPause()
{
if (mAdView != null)
{
mAdView.pause();
}
super.onPause();
}
/** Called when returning to the activity */
#Override
public void onResume()
{
super.onResume();
if (mAdView != null)
{
mAdView.resume();
}
}
/** Called before the activity is destroyed */
#Override
public void onDestroy() {
if (mAdView != null)
{
mAdView.destroy();
}
super.onDestroy();
}
}
Now im unsure whether it is my code that not generating the device ID or a problem with my created AVD device. The tutorials i seen have something like this
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC")
Now i don't know if the last line is the code given by LogCat or is something that i just have to put in. I noticed the developer.google website has a different code so i assume i don't need to include in my code since i have not got it yet.
Please help. thank you.
UPDATE 1
I added this code inside On Resume inside my main activity
#Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
int isAvaiable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(isAvaiable == ConnectionResult.SUCCESS)
{
Log.d("TEST", "GPS IS OK");
}
else if(isAvaiable == ConnectionResult.SERVICE_MISSING || isAvaiable == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || isAvaiable == ConnectionResult.SERVICE_DISABLED)
{
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvaiable, this, 1);
dialog.show();
}
}
The API to test banners should be 17 or higher. You have a good answer here that explains it. GPS in emulator.
For the problems related to launch the emulator the only suggestion I can give you is trying VM Acceleration and use an smaller screen.
You can try other emulators like x86Emulator and download and the last ISO versions 4.4. In my case the default android emulator took 10-12minutes to be responsive in a ldpi, with the other only 2 in a hdpi.
About the addTestDevice, I think AdRequest.DEVICE_ID_EMULATOR is enough, but if you see in the logcat the MD5 of your device ID then add this hash.
Last but not least, remember to check if GPS are installed at the beginning, it is explained on the DOCS.
To verify the Google Play services version, call isGooglePlayServicesAvailable(). If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update.
So you will avoid errors.
I have read everything about how to implement the Custom Events in the Admob Mediation.
I have added the full packaged class name and everything is set in the Admob portal.
This is the class implementation done
public class CustomEvent implements CustomEventBanner, AdListener{
private CustomEventBannerListener bannerListener;
private AdView adView;
#Override
public void requestBannerAd(final CustomEventBannerListener listener,
final Activity activity,
String label,
String serverParameter,
AdSize adSize,
MediationAdRequest mediationAdRequest) {
// Keep the custom event listener for use later.
this.bannerListener = listener;
// Determine the best ad format to use given the adSize. If the adSize
// isn't appropriate for any format, an ad will not fill.
AdSize bestAdSize = adSize = adSize.findBestSize(
AdSize.BANNER,
AdSize.IAB_BANNER,
AdSize.IAB_LEADERBOARD,
AdSize.IAB_MRECT,
AdSize.IAB_WIDE_SKYSCRAPER);
if (bestAdSize == null) {
listener.onFailedToReceiveAd();
return;
}
// Initialize an AdView with the bestAdSize and the publisher ID.
// The publisher ID is the server parameter that you gave when creating
// the custom event.
this.adView = new AdView(activity, bestAdSize, serverParameter);
// Set the listener to register for events.
this.adView.setAdListener(this);
// Generate an ad request using custom targeting values provided in the
// MediationAdRequest.
AdRequest adRequest = new AdRequest()
.setBirthday(mediationAdRequest.getBirthday())
.setGender(mediationAdRequest.getGender())
.setKeywords(mediationAdRequest.getKeywords())
.setLocation(mediationAdRequest.getLocation());
if (mediationAdRequest.isTesting()) {
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
}
// Load the ad with the ad request.
this.adView.loadAd(adRequest);
}
#Override
public void onReceiveAd(Ad ad) {
this.bannerListener.onReceivedAd(this.adView);
}
#Override
public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
this.bannerListener.onFailedToReceiveAd();
}
#Override
public void onPresentScreen(Ad ad) {
this.bannerListener.onClick();
this.bannerListener.onPresentScreen();
}
#Override
public void onDismissScreen(Ad ad) {
this.bannerListener.onDismissScreen();
}
#Override
public void onLeaveApplication(Ad ad) {
this.bannerListener.onLeaveApplication();
}
}
The problem is that I really dont know how to add use my layout.add(adview) in the onReceivedAd(),
Any inputs would be helpful.
Custom Events are a little different compared to normal AdMob implementation. In requestBannerAd you create your ad network's adview, and request an ad. Once an ad is received (in this the onReceiveAd callback), you invoke:
this.bannerListener.onReceivedAd(this.adView);
You're already doing this in your code. When invoking this, you're telling the AdMob Mediation layer "Hey, I successfully loaded an ad, and here is my view for you to show." The Mediation layer takes in your adview and essentially calls layout.addView(adView) on your behalf (it adds it as a child of the main AdView you defined in your app).
So in your case, this code should just work.
I am using AdMob in my Android application and want to display a backup ad if AdMob doesn't fill. I hook into the _adView.setAdListener( but when no ad is returned, onFailedToReceiveAd does not fire like I would expect it to. When an ad is returned, onReceiveAd fires, so I know I am hooked up correctly. LogCat tells me: "No fill. Server replied that no ads are available." which seems correct. Any ideas?
public class MultipleAdView extends LinearLayout {
private AdView _adView = null;
private WebView _webView = null;
private Context _context = null;
/*
* Constructor from parent class.
*/
public MultipleAdView(Context context) {
super(context, null);
_context = context;
}
public MultipleAdView(Context context, AttributeSet attrs){
super(context, attrs);
_context = context;
}
public void initialize(Activity activity){
_adView = new AdView(activity);
_adView.setAdListener(new AdListener() {
#Override
public void onReceiveRefreshedAd(AdView arg0) {
int j = 0;
j++;
}
#Override
public void onReceiveAd(AdView arg0) {
// Just here for breakpoint - gets in here fine when ad is returned
int j = 0;
j++;
}
#Override
public void onFailedToReceiveRefreshedAd(AdView arg0) {
// Is never called when no ad is returned
loadBackupAd();
}
#Override
public void onFailedToReceiveAd(AdView arg0) {
// Is never called when no ad is returned
loadBackupAd();
}
private void loadBackupAd(){
// Load backup ad here
}
});
addView(_adView, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
}
I figured this out recently. You should be aware that onFailedToReceiveAd and onFailedToReceiveRefreshedAd seem to have special conditions which I only determined through testing.
onFailedToReceiveAd will only be called when the initial call to get the first ad for an adview does not return any ad. If an ad is received during your first request for an ad, either with refreshAd or setting the interval, you will never get this message.
onFailedToReceiveRefreshedAd does not seem to get fired as long as the adView is automatically refreshing. It only seems to get called when refreshAd is called directly (same with onReceivedRefreshedAd). See my edit below...
Ad whirl is a better option if you're looking to spread across multiple available ad networks. It handles the rationing on the server but I've still run into problems where its seems to be out of sync with admob. Fortunately, the adwhirl code is open source so you can take a look at what its doing.
Your question caused me to do some digging. From the Android AdWhirl SDK:
public void onReceiveAd(AdView adView) {
Log.d(AdWhirlUtil.ADWHIRL, "AdMob success");
AdWhirlLayout adWhirlLayout = adWhirlLayoutReference.get();
if (adWhirlLayout == null) {
return;
}
adWhirlLayout.adWhirlManager.resetRollover();
adWhirlLayout.handler.post(new ViewAdRunnable(adWhirlLayout, adView));
adWhirlLayout.rotateThreadedDelayed();
}
public void onFailedToReceiveAd(AdView adView) {
Log.d(AdWhirlUtil.ADWHIRL, "AdMob failure");
adView.setAdListener(null);
AdWhirlLayout adWhirlLayout = adWhirlLayoutReference.get();
if (adWhirlLayout == null) {
return;
}
adWhirlLayout.rollover();
}
public void onFailedToReceiveRefreshedAd(AdView adView) {
// Don't call adView.refreshAd so this is never called.
}
public void onReceiveRefreshedAd(AdView adView) {
// Don't call adView.refreshAd so this is never called.
}
}
This suggests to me that the mechanism for getting onFailedToReceiveRefreshedAd may indeed be to setup your own ad interval Timer using TimerTask or the sort. If you did this while disabling automatic refresh, my guess is that you'd have better luck.
You could try implementing onFailedToReceiveRefreshedAd also.