Esempio n. 1
0
            private void Upload(Android.Net.Uri uri)
            {
                try {
                    // The projection contains the columns we want to return in our query.
                    string[] projection = new[] {
                        Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data,
                        Android.Provider.MediaStore.Images.Media.InterfaceConsts.MimeType,
                        Android.Provider.MediaStore.Images.Media.InterfaceConsts.Size
                    };
                    using (ICursor cursor = this.Activity.ContentResolver.Query(uri, projection, null, null, null))
                    {
                        if (cursor != null)
                        {
                            cursor.MoveToFirst();
                            string path = cursor.GetString(cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data));
                            string mime = cursor.GetString(cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.MimeType));
                            int    size = cursor.GetInt(cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Size));
                            cursor.Close();

                            if (path == null)
                            {
                                Toast.MakeText(this.Activity, "Uploading file must be located in local storage.", ToastLength.Long).Show();
                            }
                            else
                            {
                                SendBirdSDK.UploadFile(path, mime, size, "", new SendBirdFileUploadEventHandler(
                                                           (sender, e) => {
                                    if (e.Exception != null)
                                    {
                                        Console.WriteLine(e.Exception.StackTrace);
                                        Toast.MakeText(this.Activity, "Fail to upload the file.", ToastLength.Long).Show();
                                    }

                                    SendBirdSDK.SendFile(e.FileInfo);
                                }
                                                           ));
                            }
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine(e.StackTrace);
                    Toast.MakeText(this.Activity, "Fail to upload the file.", ToastLength.Long).Show();
                }
            }