Ejemplo n.º 1
0
            private async void UploadMultiplePhotosToWall(object sender, EventArgs e)
            {
                var photo    = GetPhoto();
                var request1 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.9f)), 0, OwnerId);
                var request2 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.5f)), 0, OwnerId);
                var request3 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.1f)), 0, OwnerId);
                var request4 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.PngImage()), 0, OwnerId);

                var batch     = new VKBatchRequest(request1, request2, request3, request4);
                var responses = await batch.ExecuteAsync();

                try {
                    RecycleBitmap(photo);
                    var resp        = responses.Select(r => ((VKPhotoArray)r.ParsedModel) [0]);
                    var attachments = new VKAttachments();
                    attachments.AddRange(resp);
                    MakePost("I just uploaded multiple files from the VK Xamarin.Android SDK!", attachments);
                } catch (VKException ex) {
                    ShowError(ex.Error);
                }
            }
Ejemplo n.º 2
0
            private async void MakePost(string message, VKAttachments attachments = null)
            {
                var post = VKApi.Wall.Post(new VKParameters(new Dictionary <string, Java.Lang.Object> {
                    { VKApiConst.OwnerId, OwnerId },
                    { VKApiConst.Attachments, attachments ?? new VKAttachments() },
                    { VKApiConst.Message, message }
                }));

                post.SetModelClass <VKWallPostResult> ();
                try {
                    var response = await post.ExecuteAsync();

                    if (IsAdded)
                    {
                        var result = (VKWallPostResult)response.ParsedModel;
                        var uri    = string.Format("https://vk.com/wall{0}_{1}", OwnerId, result.post_id);
                        var i      = new Intent(Intent.ActionView, Uri.Parse(uri));
                        StartActivity(i);
                    }
                } catch (VKException ex) {
                    ShowError(ex.Error);
                }
            }