Load achievements from Google Play without any Unity plugins only native code - c#

It is possible to use this code from Unity samples:
//C#
Social.LoadAchievements (achievements => {
if (achievements.Length > 0) {
Debug.Log ("Got " + achievements.Length + " achievement instances");
string myAchievements = "My achievements:\n";
foreach (IAchievement achievement in achievements)
{
myAchievements += "\t" +
achievement.id + " " +
achievement.percentCompleted + " " +
achievement.completed + " " +
achievement.lastReportedDate + "\n";
}
Debug.Log (myAchievements);
}
else
Debug.Log ("No achievements returned");
});
and get Google Play achievements. Or it's works only for iOs devices and for Android I have to use some plugins?
This script as I understood works only for iOs devise not for Android.
Why don't use standard Unity Google plugin?
- Because they don't teach it to load achievements.
/// <summary>
/// Not implemented yet. Calls the callback with an empty list.
/// </summary>
public void LoadAchievements(Action<IAchievement[]> callback) {
Logger.w("PlayGamesPlatform.LoadAchievements is not implemented.");
if (callback != null) {
callback.Invoke(new IAchievement[0]);
}
}

Why not to use the official Google Play Services plugin for Unity?
Here's a Link to an official Google Developer web site, where you can find all the information you need to set it up correctly.
This plugin works on both Android and iOS Devices!

Related

Adding users to ZKTeco access door using Push SDK

I'm trying to add users to the Door Access Control Device: "inBio 260"
I'm told I need to use the Push/Pull SDK to do that.
public bool AddUser(User u) {
return axCZKEM1.SSR_SetDeviceData(machineNumber, "user", u + "\r\n", "");
}
class User {
...
public override string ToString()
{
return
"CardNo=" + ID + "\t" +
"Pin=" + Pin + "\t" +
"Name=" + Name + "\t" +
"Password=" + Password + "\t" +
"StartTime=" + StartTime + "\t" +
"EndTime=" + EndTime;
}
}
public bool AddFingerprint(Fingerprint p)
{
return
IsPinValid(p.Pin) &&
p.Template != null &&
p.Template.Length > 100 &&
axCZKEM1.SSR_SetDeviceData(machineNumber, "templatev10", p + "\r\n", "");
}
}
class Fingerprint {
...
public override string ToString()
{
int size = Convert.FromBase64String(Template).Length;
return
"Size=" + size +
"\tPin=" + Pin +
"\tFingerID=" + FingerID +
"\tValid=1\tTemplate=" + Template +
"\tEndTag=" + EndTag;
}
}
I use "ZKAccess 3.5" to check and I find the users I added and everything seems fine.
But suddenly the machine will report 0 valid fingerprints. And the doors won't open.
Calling AddFingerprint to restore the lost fingerprint returns a false "true", i.e. nothing was added and the machine still has 0 fingerprints left.
Note: ZKAccess is limited to 2000 users, I added 2600+ users.
Update: ZKAccess has 2654 users in its database, clicking sync to device only restores the 900 users that where added using ZKAccess itself (foul play suspected).
Update: I confused push & pull sdk, they are not the same. PullSDK is free, push SDK is private to ZKTeco
ZKAccess3.5 deleted all data because the limit of the free version was exceeded.
EDIT: Just for anyone looking for an answer, Push sdk is a private sdk used only by ZKteco. Pull sdk how ever is free but has no documentation. I wrote a wrapper in C#: code

How would I detect and display an HTTP error message(404) on Xamarin if I'm using an API wrapper?

I am currently using Xamarin to create a multiplatform application for the phone. The app idea is basically a Pokemon encyclopedia that utilizes the PokeAPi (https://pokeapi.co/) and also uses the following wrapper library (https://gitlab.com/PoroCYon/PokeApi.NET). Currently, I want it to where if the user types in an incorrect Pokemon into the search bar, it will return an alert error to the user. However, every time I test it and enter in an invalid pokemon, the application stops and Visual Studio/Xamarin informs me of a HTTP404 error. How would I go about this?
I've tried using comparison statements in where if the API call doesn't find the pokemon name, it should pop up with an alert, but VS/Xamarin will stop running the application and display a Http404 exception. I really dont know where to go at this point.
'''
async Task PullData()
{
LoadingIcon.IsRunning = true;
string newPokemon = PokemonFind.Text;
Pokemon p = await DataFetcher.GetNamedApiObject<Pokemon>(newPokemon);
string PokemonName = p.Name;
int PokemonHeight = p.Height;
int PokemonWeight = p.Mass;
int PokemonXp = p.BaseExperience;
int PokemonOrder = p.Order;
OrderLabel.Text = "#" + PokemonOrder;
NameLabel.Text = "Name: " + PokemonName;
HeightWeightLabel.Text = "Height/Weight: " + PokemonHeight.ToString() +" dm " + "/" + PokemonWeight.ToString() + " hg";
ExpLabel.Text = "Experience on defeat: " + PokemonXp.ToString() + "XP";
LoadingIcon.IsRunning = false;
}
'''
I expected it to display an alert message instead of VS/Xamarin stopping the program and throwing me an HTTP404 exception.
Wrap your call inside a try/catch block
try
{
async Task PullData()
}
catch(HttpRequestException ex)
{
//Shows an alert error to the user
}

Facebook C# SDK get user language/region

I'm using the Facebook C# SDK. How can I get language of the user, so I can display all messages accordingly without forcing the user to choose his preferred language manually?
If you are developing a web app, then you can use Accept-Language Http header to detect the language
EDIT 1
For winforms application, you can use System.Globalization.CultureInfo.CurrentCulture.Name .
EDIT2
To get the locale using FB REST API :
dynamic fbResult = new Uri("https://graph.facebook.com/AngelaMerkel?access_token=AAABkECTD......").GetDynamicJsonObject();
Console.WriteLine(
fbResult.locale ?? "-" + " > " + //<----
fbResult.location.country + " " + //<----
fbResult.location.city + " " + //<----
fbResult.name + " " +
fbResult.gender + " " +
fbResult.link + " " +
fbResult.updated_time);
You can find info about my extension method GetDynamicJsonObject here

Media player in Windows Phone 7

I am using the media player in Windows Phone 7 to play the music in the phone song collection. But when it play the music they will be an exception and the error is stating
FrameworkDispatcher.Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly.
How should i go about modifying my code?
private void songBtn_Click(object sender, RoutedEventArgs e)
{
using (var ml = new MediaLibrary())
{
foreach (var song in ml.Songs)
{
System.Diagnostics.Debug.WriteLine(song.Artist + " " + song.Name);
MessageBox.Show(song.Artist + " " + song.Name);
}
MediaPlayer.Play(ml.Songs[0]);
}
}
You have to call
FrameworkDispatcher.Update()
whenever you make a call to an XNA media library
so your code should look like this
using (var ml = new MediaLibrary())
{
foreach (var song in ml.Songs)
{
System.Diagnostics.Debug.WriteLine(song.Artist + " " + song.Name);
MessageBox.Show(song.Artist + " " + song.Name);
}
FrameworkDispatcher.Update();
MediaPlayer.Play(ml.Songs[0]);
}
The error is occouring because you're using the XNA Framework in a regular Windows Phone 7 application.
If you read the error description, you would gotten this link to MSDN: Enable XNA Framework Events in Windows Phone Applications , which explains precisely what to do.

Mute/unmute, Change master volume in Windows 7 x64 with C#

How can I adjust master volume in Windows 7 with C#?
I have seen an excellent implementation using winmm.dll here, but it works with XP and not with Windows 7.
I used the nuget package Naudio successfully with this code:
public void SetVolume(int level)
{
try
{
//Instantiate an Enumerator to find audio devices
NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
//Get all the devices, no matter what condition or status
NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
//Loop through all devices
foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
{
try
{
if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
{
var newVolume = (float)Math.Max(Math.Min(level, 100),0) / (float)100;
//Set at maximum volume
dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume;
dev.AudioEndpointVolume.Mute = level == 0;
//Get its audio volume
_log.Info("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
}
else
{
_log.Debug("Ignoring device " + dev.FriendlyName + " with state " + dev.State);
}
}
catch (Exception ex)
{
//Do something with exception when an audio endpoint could not be muted
_log.Warn(dev.FriendlyName + " could not be muted with error " + ex);
}
}
}
catch (Exception ex)
{
//When something happend that prevent us to iterate through the devices
_log.Warn("Could not enumerate devices due to an excepion: " + ex.Message);
}
}
CodeProject has a very good sample here. Note that it relies on COM interop completely (check COM interface like IAudioEndpointVolume and IAudioMeterInformation on MSDN if you are interested in implementation details), and works ONLY for Vista/Win7 and higher.
Minimum supported client: Windows Vista
Minimum supported server: Windows Server 2008

Categories