UWP: Can't load and show Interstitial video ad - xaml

I'm trying to monetize my app with Universal Windows. I followed the official tutorials but when I tried to load an interstitial ad, always I'm getting this errors:
Interstitial ad is not ready. With this error code: ClientConfiguration.
Failed to make http requestError. With this error code: NetworkConnectionFailure.
I don't know what I am missing.
This is my code:
public sealed partial class Myclass: Page {
InterstitialAd MyVideoAd;
public MyClass() {
this.InitializeComponent();
var MyAppId = "d25517cb-12d4-4699-8bdc-52040c712cab";
var MyAdUnitId = "11389925";
MyVideoAd = new InterstitialAd();
MyVideoAd.ErrorOccurred += MyVideoAd_ErrorOccurred;
MyVideoAd.RequestAd(AdType.Video, MyAppId, MyAdUnitId);
}
private void MyVideoAd_ErrorOccurred(object sender, AdErrorEventArgs e) {
String errrorMessage = e.ErrorMessage;
String errorCode = e.ErrorCode;
}
private void showInterstitial(object sender, TappedRoutedEventArgs e) {
MyVideoAd.Show();
}
}
When I execute the application, a few seconds after the MyVideoAd_ErrorOccurred method is launched with the values of errorMessage and errorCode as I've said. That happens on my Windows 10 mobile device and in the Desktop machine execution. The codes of adUnit and application id are the provided in the Microsoft page for tests.
I hope that you can help me.

For UWP app, please install Microsoft Universal Ad Client SDK and use AdMediatorControl.
References:
Install the Universal Ad Client SDK
Add and use the ad mediator control
Check my sample: https://github.com/Myfreedom614/UWP-Samples/tree/master/AdClientUWPApp

Be sure to have these 3 Capabilities defined inside your manifest:
<Capabilities>
...
<Capability Name="internetClient"/>
<Capability Name="internetClientServer"/>
<Capability Name="privateNetworkClientServer"/>
...
</Capabilities>

The video hasn't finished loading. you need to give it enough time for that. also you need to make sure it is loaded before calling it with.
if ((InterstitialAdState.Ready) == (MyVideoAd.State))
{
MyVideoAd.Show();
}

Related

VS2022 - Hot reload applying changes successfully but not reflecting in app for a simple console app

I have a simple .net 6.0 console with the following code running on visual studio 2022. I change the Console.WriteLine text while the app is running and I get a log message from hot reload saying "Changes were successfully applied.". But nothing happens on my app. What am I doing wrong? I tried with and without debugger as per suggestions on other stack overflow threads. But no luck it still does not work. Here's my code.
using System;
namespace TestVS2022
{
public static class Program
{
public static void Main(string[] args)
{
while (true)
{
System.Console.WriteLine($"Hello World.");
Thread.Sleep(1000);
}
}
}
}

Android Accessibility Service stopped working after a day or two on Oreo

Background:
I have a class which extends from AccessibilityService. Whenever a window is changed following function is called which gives me the application name of the foreground application.
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
Following is the configuration I set:
#Override
protected void onServiceConnected() {
super.onServiceConnected();
//Configure these here for compatibility with API 13 and below.
AccessibilityServiceInfo config = new AccessibilityServiceInfo();
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
if (Build.VERSION.SDK_INT >= 16) { //Just in case this helps
config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
}
setServiceInfo(config);
}
AccessibilityService.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="#string/accessibility_explanation"
android:accessibilityEventTypes="typeWindowStateChanged|typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken|feedbackHaptic|feedbackAudible|feedbackVisual|feedbackGeneric|feedbackAllMask"
android:notificationTimeout="100" android:canRetrieveWindowContent="true" />
The Problem:
It works fine for some time, but after a day or two it suddenly stops working. It doesn't call the onAccessibilityEvent(AccessibilityEvent event) function. Although the accessibility service of this application is enabled but still it doesn't show the application name when window is changed.
May be it doesn't work if the application comes back from sleep mode? I had to reinstall the application on top of my debug build and then again it started working but for how long.
Question: How can I make sure it always return me the application name when window is changed?
Just restart your app. This is because Accessibility Service is managed by the Android OS, so if any thing causes your service to crash, it will be killed and rescheduled to be started at some time in the fture that you can not control. So it is possible that your service has been killed.

Http error in background task Windows 10 mobile (UWP)

I have a background task which executes a http request, but only works a small number of times. The error returned is: "The server name or address could not be resolved". The url is correct and works fine if I execute it from main app.
The code is a simple http request with a "HttpClient":
public async void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
try
{
using (var client = new HttpClient())
{
var c = await client.GetStringAsync("http://www.google.com");
}
}
catch (Exception e)
{
}
finally
{
_deferral.Complete();
}
}
As I've said, the same url Works sometimes and sometimes not, and yes, I'm checking internet connection before each request.
Any ideas please?
EDITED:
Here is my phone info:
And here is the repo with a test app demonstrating the issue: https://github.com/CabuxaMapache/BackgroundTask.Test
EDITED 2:
I've tested the app in a Lumia 640 with the same results, over 100 executions and only 10 of them OK. Here is the L640 info:
Thanks in advance
So, finally, the answer is here: https://learn.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.Background.BackgroundTaskBuilder#properties_, thanks Dave Smits!

Was able to push logs but failed while calling WLClient.connect()

I am working on IBM MobileFirst client being android native app.
I have a weird issue I am writing the following code to initialize WLClient.
WLClient client = WLClient.createInstance(context);
client.connect(new WLResponseListener() {
#Override
public void onSuccess(WLResponse wlResponse) {
Log.d("Success--- MFP_connect",wlResponse.getResponseText());
}
#Override
public void onFailure(WLFailResponse wlFailResponse) {
Log.d("fail-- MFP_connect",wlFailResponse.getErrorMsg());
}
});
In My android Monitor I see a log saying
fail-- MFP_connect: The service is currently not available.
But when I am trying to push logs or analytics to the server. They are reaching the server successfully.
I am connecting to http enterprise server.
What could be the issue.
#rocky solved his issue by uninstalling the app and reinstalling. The device may have been caching the previous response.

SignalR WPF Client can't reach hub deployed on IIS when IIS runs on a different system

I just play a little bit with signalR. My application has only one simple hub which is stored in an ASP.NET Application and I wrote a WPF client, which interacts via the hubconnection and the created proxy with the ASP.NET Application. Everything works fine on my local PC. I deployed the ASP.NET Application on IIS.
Now I am getting to the point...
When I type the following into my browser on my own PC (pcthi-and)
http://pcthi-and:8080/signalr/hubs
I'll get what I want
When I type the same url into a browser of another pc I'll get the same response and everything looks fine.
But my Application only works on my pc and not on the other one. When I start the hubconnection on the other pc I don't get a connectionId.
I tried to change the url to my IP-Address without effect.
Browser call to hub works but the Application doesn't work.
The call looks like this:
private bool tryToConnectToCoffeService()
{
try
{
this.hubConnection = new HubConnection(ConfigurationManager.ConnectionStrings["coffeeConnection"].ConnectionString);
this.hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
this.coffeeService = this.hubConnection.CreateHubProxy("coffee");
this.hubConnection.Start();
if (string.IsNullOrEmpty(hubConnection.ConnectionId))
{
return false;
}
return true;
}
catch(Exception ex)
{
return false;
}
}
The Global.asax:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
The hub like this
[HubName("coffee")]
public class CoffeeHub : Hub
{
My Hub Connection String is this:
"http://pcthi-and:8080/"
Or:
"http://My-Current-IP-Address:8080/"
I use SignalR 1.0 rc2.
Does anyone have an idea? Thanks for helping.
Cheers
Frank
I think you need to change
hubConnection.Start();
to
hubConnection.Start().Wait();
If you are running .NET 4.5 you could make the tryToConnectToCoffeService method async and then await when you start the hub connection.
await hubConnection.Start();
It likely works today on localhost because the client can finish connecting before if (string.IsNullOrEmpty(hubConnection.ConnectionId)) executes.
It is probably taking longer to connect from another machine which exposes the race condition present when you don't wait for HubConnection.Start() to complete.