guys. I'm trying to use vk api sdk in Xamarin.Android. I create a request:
var token = VKHelper.GetVkUserToken(App.Data.Setting.List);
var iparams = new Dictionary<string, Java.Lang.Object>();
iparams.Add(VKApiConst.UserId, VKBuffer.Friend.Id);
iparams.Add("type", "invite");
iparams.Add("access_token", token);
v = new VKRequest("apps.sendRequest", new VKParameters(iparams));
By clicking in button I call ExecuteWithListener:
v.ExecuteWithListener(new ReqvList(new Action(o =>
{
RunOnUiThread(() =>
{
if (o.IsComplete)
{
try
{
showCustomAlert(Resource.Drawable.checkmark, GetString(Resource.String.SentInvite), Android.Graphics.Color.Argb(100, 0, 0, 200));
}
catch { }
}
else
{
try
{
showCustomAlert(Resource.Drawable.ic_post, GetString(Resource.String.NotSentInvite) + "\n" + GetString(o.MessageId), Android.Graphics.Color.Argb(100, 200, 0, 0));
}
catch { }
}
});
})));
Listener:
public class ReqvList : VKRequest.VKRequestListener
{
Action<CallBackVKResponse> Complete;
CallBackVKResponse callBackVKResponse = new CallBackVKResponse
{
IsComplete = false,
MessageId = 0
};
public ReqvList(Action<CallBackVKResponse> Complete)
{
this.Complete = Complete;
}
public override void OnComplete(VKResponse p0)
{
base.OnComplete(p0);
var response = p0.Json.ToString();
callBackVKResponse.IsComplete = true;
Complete(callBackVKResponse);
}
public override void OnError(VKError p0)
{
int errorCode = p0.ApiError != null ? p0.ApiError.ErrorCode : 0;
callBackVKResponse.IsComplete = false;
if (errorCode == 15)
callBackVKResponse.MessageId = Resource.String.VkInviteError;
Complete(callBackVKResponse);
base.OnError(p0);
}
}
Summary: if I press to invite a friend, I will see a "vkontakte" dialog window with suggest message (here you can accept or skip). If I press "invite" a friend which has disabled to invite him (or her) then it works fine. This is:
....
else
{
try
{
showCustomAlert(Resource.Drawable.ic_post, GetString(Resource.String.NotSentInvite) + "\n" + GetString(o.MessageId), Android.Graphics.Color.Argb(100, 200, 0, 0));
}
catch { }
}
....
But if a user has enabled to invite him (or her) then listener won't work and my app will freeze. In the phone you can press back button and the app will unfreez and after I can press again the button - invite will has worked fine. Listener OnComplete works only the second time. This is:
...
if (o.IsComplete)
{
try
{
showCustomAlert(Resource.Drawable.checkmark, GetString(Resource.String.SentInvite), Android.Graphics.Color.Argb(100, 0, 0, 200));
}
catch { }
}
...
Help please.