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.
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 working on a project where I want to upload files after developer authentication is complete. I am using AWS Cognito for authentication. Problem here is sometimes TransferUtility does not trigger onProgresschanged. Although it does not trigger onprogresschanged but the file is getting uploaded. I want to show a progressbar on the UI for every upload.It is working sometimes and sometimes it is not working.
Here is how I am uploading files.
public void upload() {
ClientConfiguration configuration = new ClientConfiguration();
configuration.setProtocol(Protocol.HTTP);
configuration.setSocketTimeout(5 * 10000);
configuration.setConnectionTimeout(5 * 10000);
configuration.setMaxErrorRetry(3);
if(sS3Client==null) {
sS3Client = new AmazonS3Client(credentials,configuration);
}
sTransferUtility = new TransferUtility(sS3Client,
this.ctx);
observer = sTransferUtility.upload("bucketer", "Filename", "file");
observer.setTransferListener(new UploadListener(progress));
}
private class UploadListener implements TransferListener {
ProgressBar progressBar;
public UploadListener(ProgressBar progress){
this.progressBar = progress;
}
#Override
public void onStateChanged(int i, TransferState transferState) {
Log.d("STATUS CHANGED:".concat(String.valueOf(i)),transferState.toString());
switch (transferState.toString())
{
case "IN_PROGRESS":
{
Log.d("IN_PROGRESS", "IN_PROGRESS");
}
break;
case "COMPLETED":
{
Log.d("COMPLETED COMPLETED", "COMPLETED");
}
break;
}
}
#Override
public void onProgressChanged(int i, long l, long l1) {
updator();
this.progressBar.setProgress(transferprogres);
}
#Override
public void onError(int i, Exception e) {
Log.d("UPOLADING ERROR:",String.valueOf(e));
}
}
public void updator(){
transferprogres = (int) ((double) observer.getBytesTransferred() * 100 / observer.getBytesTotal());
}
The code above is a part of total project. For more details comment.
Why is it showing weird performance?
See Aws S3 TransferService Upload failing without errors and https://github.com/aws/aws-sdk-android/issues/101. In short, v2.2.12 requires user to manage the life cycle of transfer listeners as transfer utility keeps only weak references of them. You can make the listener or the observer as class variable to prevent it from garbage collected. Anyway, we are tweaking the listeners in future releases. Sorry for the trouble and please stay tuned.
Is there any way to preload fullscreen ad on Unity? Right now when we call it using
revmob.ShowFullscreen();
when we create end game screen. But most of the time it loads after 5/10 secs later which is in-game most probably if you press restart, so it shows a full screen ad during gameplay.
I've found some ways to preload it on native android and tried same function to see if they exists in Unity but no luck.
Thanks.
Yes! You can use the following code:
private RevMobFullscreen fullscreen;
fullscreen = revmob.CreateFullscreen();
fullscreen.show();
If you need more information, you can access RevMob mobile ad network website: https://www.revmobmobileadnetwork.com
It will be better to add this code to the Create statement:
private RevMobFullscreen fullscreen;
fullscreen = revmob.CreateFullscreen();
...and then also this code to the listener:
RevMobAdsListener revmobListener = new RevMobAdsListener() {
// Required
#Override
public void onRevMobSessionIsStarted() {
fullscreen.show();
}
(...)
}
This will show the fullscreen ad.
You can do like this to preload revmob videos in unity. But there are memory leaks in revmob unity videos and they might fix that in 9.2.x...
REVMOB_APP_IDS = new Dictionary<string, string>() {
{ "Android", androidMediaId},
{ "IOS", iosMediaId }
};
revmob = RevMob.Start (REVMOB_APP_IDS, gameObject.name);
public void SessionIsStarted ()
{
CacheVideoInterstitial("Bootup");
}
public void CacheVideoInterstitial(string location) {
DestroyVideo();
StartCoroutine(CacheAfterEndofFrame(location));
}
IEnumerator CacheAfterEndofFrame(string location) {
yield return null;
fullscreenVideo = revmob.CreateVideo(location);
}
void DestroyVideo() {
if( fullscreenVideo != null ) {
fullscreenVideo.Hide();
//fullscreenVideo.Release();
//fullscreenVideo = null;
}
}
// revmob ad closing delegate
public void UserClosedTheAd (string revMobAdType)
{
DestroyVideo();
CacheVideoInterstitial(this.location);
}
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);
}
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.