I have a problem with AdColony-UnitySDK.
When AdColony's video is finish playing, OnVideoFinished() method don't be called.
In this case, the following sources work well in iOS. And also, the server receive the success callback both device. So, only Android device that is not work.
Here is the source code, where AdColony is implemented:
public void initializeAdColony(){
try {
//Delegates
AdColony.OnVideoFinished += (adshown)=>{
if (adshown) {
AdColonyLog("OnVideoFinished", "Completed");
GameBGM.Instance.PlayWaiting();
CallAdColonySuccessCallback("Success", v4vcSuccess,v4vcFail);
} else {
AdColonyLog("OnVideoFinished", "Failed");
CallAdColonyFailureCallback("Fail", v4vcSuccess,v4vcFail);
}
};
AdColony.OnV4VCResult += (videoSuccessCallbacks,name,amount)=>{
if(videoSuccessCallbacks)
{
AdColonyLog("OnV4VCResult","V4VC SUCCESS: name = " + name + ", amount = " + amount);
returnReward = name;
}
else
{
AdColonyLog("OnV4VCResult","V4VC FAILED!");
CallAdColonyFailureCallback("Fail", v4vcSuccess,v4vcFail);
}
};
//customID
AdColony.SetCustomID(LoginInfo.Instance.id);
//configure
AdColony.Configure(
CurrentBundleVersion.version,
AdColonyData.appID(),
AdColonyData.zoneIDs[AdColonyData.Zone1],
AdColonyData.zoneIDs[AdColonyData.Zone2],
AdColonyData.zoneIDs[AdColonyData.Zone3],
AdColonyData.zoneIDs[AdColonyData.Zone4],
AdColonyData.zoneIDs[AdColonyData.Zone5]
);
//FinishInit
AdColonyIsInit = true;
AdColonyLog("Initiallize", "Complete");
} catch (Exception e){
//Error
AdColonyLog("Initiallize", e.Message);
}
}
And here is the method where AdColony's video show:
public void ShowAdColonyVideo(System.Action successCallback, System.Action failureCallback){
//InitAdColony
if (!AdColonyIsInit) {
initializeAdColony();
}
//Setup CallbackAction;
shownVideo = false;
v4vcSuccess = successCallback;
v4vcFail = failureCallback;
//Check
foreach (string key in AdColonyData.services) {
AdColonyLog("LoadKey", key + ":"+ AdColonyData.zoneIDs[key]);
if (shownVideo) {
break;
}
if (AdColony.IsV4VCAvailable (AdColonyData.zoneIDs [key])) {
AdColonyLog ("ShowAdColonyVideo", "Video available");
GameBGM.Instance.StopMusic ();
shownVideo = true;
AdColony.ShowV4VC (false, AdColonyData.zoneIDs [key]);
break;
} else {
AdColonyLog ("ShowAdColonyVideo", "Video unavailable");
}
}
if (!shownVideo) {
failureCallback ();
}
}
Do you please suggest me how to solve this issue? Thank you.
This is a known issue at AdColony and we will be releasing a fix in a pending release.
We will update this post once it has been released at:
https://github.com/AdColony/AdColony-Unity-SDK
Related
I'm working with C# xamarin forms android and I'm trying to go back using OnBackButtonPressed. It kind of works but my problem is that the user has to touch 2 times to go back. I will left a photo below to explain my point. But basically the user goes from Home page to Scaner page and when he touch buttom back when he is scanning doesn't come back to home page. He has to touch 2 times and i don't want that. I need that when he touches the buttom back he goes to the home page.
my scanPage.xaml.cs:
protected override bool OnBackButtonPressed()
{
try
{
if (Shell.Current.FlyoutIsPresented == false)
{
Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
else
{
Shell.Current.FlyoutIsPresented = false;
}
}
catch(Exception ex)
{
}
//return base.OnBackButtonPressed();
return true;
}
private async Task Scanner()
{
try
{
var scannerPage = new ZXingScannerPage();
scannerPage.AutoFocus();
scannerPage.Title = "Scanner";
using (SemaphoreSlim semaphoreSlim = new SemaphoreSlim(0, 1))
{
scannerPage.OnScanResult += (result) =>
{
scannerPage.IsScanning = false;
string resultado = Convert.ToString(result);
if (resultado.Contains("http") || resultado.Contains("https") || !resultado.Contains("\t"))
{
Navigation.PopAsync();
this.DisplayAlert("Error", "QR not valid", "OK");
}
else
Device.BeginInvokeOnMainThread(async () =>
{
try
{
await Application.Current.MainPage.Navigation.PopAsync();
subs = result.Text.Split('\t');
string cadena = "var 1: " + subs[0] + "\nvar 2: " + subs[1] + "\nvar 3: " + subs[2];
numEntrega.Text = "var 2: " + subs[1];
controlScanner = true;
await this.DisplayAlert("Data", cadena, "OK");
}
catch (Exception ex)
{
checkDoubleCalled = true;
controlScanner = false;
numEntrega.Text = "";
await DisplayAlert("Error", "QR not valid.\n try again.", "OK");
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
semaphoreSlim.Release();
});
};
await Navigation.PushAsync(scannerPage);
await semaphoreSlim.WaitAsync();
}
return;
}
catch(Exception ex)
{
checkDoubleCalled = true;
controlScanner = false;
numEntrega.Text = "";
await DisplayAlert("Error", "Sorry we had a problem.", "OK");
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
return;
}
Image of my problem:
How could I resolve this problem?
Thank you very much!
I have the following code for scanning a document using WIA with a Kodak ScanMate i1120
public static Device InitScanner(string DeviceID)
{
var deviceManager = new DeviceManager();
// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;
// Loop through the list of devices
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
{
if (deviceManager.DeviceInfos[i].DeviceID == DeviceID)
{
firstScannerAvailable = deviceManager.DeviceInfos[i];
var device = firstScannerAvailable.Connect();
return _ConnectedScanner;
}
}
return _ConnectedScanner;
}
public void ScanDocument()
{
string _DeviceID = GetDeviceID(Properties.Settings.Default.DefaultDevice);
InitScanner(_DeviceID);
if (_ConnectedScanner == null)
{
MessageBox.Show("Scanner is not turned on or connected");
Lcontinue = false;
return;
}
else
{
try
{
_item = _ConnectedScanner.Items[1] as Item;
SelectDeviceDocumentHandling(_ConnectedScanner, DeviceDocumentHandling.Feeder);
//MessageBox.Show(GetDeviceProperty(_ConnectedScanner, 3078).ToString());
_MyImage = (ImageFile)_ConnectedScanner.Items[1].Transfer();
DocCount++;
}
catch (Exception ex)
{
switch (ex.HResult)
{
case -2145320959:
Lcontinue = false;
MessageBox.Show(ex.Message + Environment.NewLine + "Unknown Error");
return;
case -2145320957:
if (DocCount == 0)
{
Lcontinue = false;
//_WaitForOperator = false;
MessageBox.Show(ex.Message + Environment.NewLine + "There is no paper in the ADF");
return;
}
else
{
Lcontinue = false;
//WaitForOperator = false;
//DocCount = 0;
}
break;
case -2145320954:
if (DocCount == 0)
{
Lcontinue = false;
//_WaitForOperator = false;
MessageBox.Show(ex.Message + Environment.NewLine + "The device is busy, Please retry");
return;
}
else
{
Lcontinue = false;
DocCount = 0;
}
break;
default:
Lcontinue = false;
MessageBox.Show("Error No : " + ex.HResult + Environment.NewLine + Environment.NewLine + ex.ToString());
return;
}
}
}
}
I have two scanners on the system, a Kyocera and the Kodak, but I only want to use the Kodak for this app.
When I try to scan with the Kodak I get error
HRESULT: 0x80070021
System.IO.FileLoadException: `The process cannot access the file because another process has locked a portion of the file.
the error happens on the following line
var device = firstScannerAvailable.Connect();
I have no other scanning applications open so I am unable to figure out what is locking the file.
Can someone see what would be causing the file lock?
I`m trying to see what is wrong with my code for a tcp connection to a server in xamarin forms using the mvvm architecture. The client is connecting but when using streamReader.readLine() i get the following error:
System.IO.IOException: Unable to read data from the transport connection: Operation on non-blocking socket would block.
I´m using xamarin forms and System.Net.Sockets for the TcpClient instance. I´m trying synchronous communication for testing with the server.
I Have a TcpServer program proven to work with other devices. Below is some code to do the communication
The ViewModel of the connection properties page has the following code:
public ICommand TestConnectionCommand { get { return new
RelayCommand(sendMsg); } }
public ICommand ConnectCommand { get; set; }
public void sendMsg()
{
this.Response = new Response();
this.EthernetConn.Port = 9091;
this.EthernetConn.Ip = SelectedDevice.Ip;
if (String.IsNullOrEmpty(EthernetConn.Ip))
{
Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.IpValidation, Languages.Accept);
return;
}
if (String.IsNullOrEmpty(EthernetConn.Timeout))
{
Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.TimeoutValidation, Languages.Accept);
return;
}
this.EthernetConn.Message = "TESTING\n";
tcpService.Initialize(this.ethernetConn);
this.Response.Message = tcpService.sendMessage(this.EthernetConn);
if (this.Response.Message.Contains("FormatException"))
{
this.Response.IsSuccess = false;
Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.FormatValidation, Languages.Accept);
this.IsRunning = false;
this.IsEnabled = true;
return;
}
else if (this.Response.Message.Contains("ArgumentNullException"))
{
this.Response.IsSuccess = false;
Application.Current.MainPage.DisplayAlert(Languages.Error, this.Response.Message, Languages.Accept);
this.IsRunning = false;
this.IsEnabled = true;
return;
}
else if (this.Response.Message.Contains("SocketException"))
{
this.Response.IsSuccess = false;
Application.Current.MainPage.DisplayAlert(Languages.Error, this.Response.Message, Languages.Accept);
this.IsRunning = false;
this.IsEnabled = true;
return;
}
else if (this.Response.Message.Contains("OK"))
{
this.Response.IsSuccess = true;
}
if (this.Response.IsSuccess)
{
Application.Current.MainPage.DisplayAlert(Languages.Success, Languages.ConnEstablished, Languages.Accept);
this.IsRunning = false;
this.IsEnabled = true;
}
else
{
Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.ConnFailed, Languages.Accept);
this.IsRunning = false;
this.IsEnabled = true;
}
}
tcpService is an instance of TCPService, which has the Initialize function to establish connection and the sendMessage function where the error appears to be:
public void Initialize(EthernetConnection eth)
{
client.SendTimeout = Convert.ToInt16(eth.Timeout);
client.ReceiveTimeout = Convert.ToInt16(eth.Timeout);
client.Connect(eth.Ip, eth.Port);
}
public string sendMessage(EthernetConnection eth)
{
string response = String.Empty;
try
{
if (!client.Connected)
{
return null;
}
var writer = new StreamWriter(client.GetStream());
writer.WriteLine(eth.Message);
//Here is where the problem seems to be:
var reader = new StreamReader(client.GetStream());
response = reader.ReadLine();
return response;
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
return "ArgumentNullException: " + e;
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
return "SocketException:: " + e;
}
catch (FormatException e)
{
Console.WriteLine("SocketException: {0}", e);
return "FormatException: " + e;
}
}
I would be expecting to read the data in the ReadLine function. Also, I had some printing on the console on the server side if it recieves data and i'm seeing it is not.
Could somebody help me on where could I be wrong? A proven solution is also fine!
Thank you so much!
Whenever you use StreamWriter you need to Flush() the contents of the stream. I'll quote MSDN as the reason becomes quite clear:
Clears all buffers for the current writer and causes any buffered data
to be written to the underlying stream.
You can use it like this:
var writer = new StreamWriter(client.GetStream());
writer.AutoFlush = true;
writer.WriteLine(eth.Message);
writer.Flush();
And there is a simple demo you can check:
https://thuru.net/2012/01/07/simple-clientserver-in-c/
I want to create a service for Wifi Direct. If I try to add Reference, I don't see core->windows option in VS2013. I have updated the winSDK.
How do I add the Windows.Devices.WifiDirect api ?
you can use
public sealed class WiFiDirectDevice : IDisposable
this is a sample code to handle connections
Windows.Devices.WiFiDirect.WiFiDirectDevice wfdDevice;
private async System.Threading.Tasks.Task<String> Connect(string deviceId)
{
string result = "";
try
{
// No device Id specified.
if (String.IsNullOrEmpty(deviceId)) { return "Please specify a Wi- Fi Direct device Id."; }
// Connect to the selected Wi-Fi Direct device.
wfdDevice = await Windows.Devices.WiFiDirect.WiFiDirectDevice.FromIdAsync(deviceId);
if (wfdDevice == null)
{
result = "Connection to " + deviceId + " failed.";
}
// Register for connection status change notification.
wfdDevice.ConnectionStatusChanged += new TypedEventHandler<Windows.Devices.WiFiDirect.WiFiDirectDevice, object>(OnConnectionChanged);
// Get the EndpointPair information.
var EndpointPairCollection = wfdDevice.GetConnectionEndpointPairs();
if (EndpointPairCollection.Count > 0)
{
var endpointPair = EndpointPairCollection[0];
result = "Local IP address " + endpointPair.LocalHostName.ToString() +
" connected to remote IP address " + endpointPair.RemoteHostName.ToString();
}
else
{
result = "Connection to " + deviceId + " failed.";
}
}
catch (Exception err)
{
// Handle error.
result = "Error occurred: " + err.Message;
}
return result;
}
private void OnConnectionChanged(object sender, object arg)
{
Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus status =
(Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus)arg;
if (status == Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus.Connected)
{
// Connection successful.
}
else
{
// Disconnected.
Disconnect();
}
}
private void Disconnect()
{
if (wfdDevice != null)
{
wfdDevice.Dispose();
}
}
I am working on a project in which I have to send and recieve SMS via GSM modem in C# using AT commands. I am done with the sending part but having trouble reading sms from the sim card.
I have tried the following code and get the following response:
OK
OK
ERROR.
The code for reading the SMS is :-`
public bool ReadSms()
{
//string buffer = string.Empty;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT");
Thread.Sleep(2000);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(3000);
this.serialPort.WriteLine("AT + CMGL = ALL" + (char)(26));
Thread.Sleep(5000);
string a = this.serialPort.ReadExisting();
MessageBox.Show(a);
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
}
return true;
}
else
return false;
}
public void Opens()
{
if(this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Closes()
{
if (this.serialPort.IsOpen == true)
{
this.serialPort.Close();
}
}
`
replace your this line "this.serialPort.WriteLine("AT + CMGL = ALL" + (char)(26));"
with this one this.serialPort.WriteLine("AT+CMGL=\"ALL\"" + (char)(13));
i hope you will not get the error.
replace the line
this.serialPort.WriteLine("AT");
with
this.serialPort.WriteLine("AT" + (char)(13));
and change 26 to 13