Android 分享方式不分享文字和图片,只分享图片 - Android

Android Share method does not share text and image, only the image - Android

我有一个方法可以通过 SMS、WhatsApp、电子邮件、Fb 等分享图像,调用它时会传递一个 URL。

该方法从共享 URL 下载图像并准备发送图像(使用 Xamarin.Essentials.Share)。

问题是我在方法 属性 中连同图像一起传递了文本(需要提供一些上下文),但在共享时文本没有显示给我,只有图像,它对我来说不太好,因为它会在没有任何上下文或信息的情况下发送它。

关于如何在 Android 上传递图像和文本的任何其他想法?

也许某种自动复制然后粘贴一些文本到键盘剪贴板?

图文法:

public async Task DownloadImageAndShareIt(string URL)
        {
            try
            {
                string localPath = "";

                var webClient = new WebClient();
                webClient.DownloadDataCompleted += (s, e) =>
                {
                    byte[] bytes = new byte[e.Result.Length];
                    bytes = e.Result; // get the downloaded data
                    string documentsPath = Android.OS.Environment.GetExternalStoragePublicDirectory
                    (Android.OS.Environment.DirectoryPictures).AbsolutePath;

                    var partedURL = URL.Split('/');
                    string localFilename = partedURL[partedURL.Length - 1];
                    localFilename = "MyAPP" + localFilename;
                    localPath = System.IO.Path.Combine(documentsPath, localFilename);
                    File.WriteAllBytes(localPath, bytes); // writes to local storage

                    MediaScannerConnection.ScanFile(Application.Context, new string[] { localPath }, null, null);
                };
                var url = new Uri(URL);
                webClient.DownloadDataAsync(url);

                var partedURL = URL.Split('/');
                string localFilename = partedURL[partedURL.Length - 1];
                localFilename = "MyAPP" + localFilename;
                string documentsPath = Android.OS.Environment.GetExternalStoragePublicDirectory
                    (Android.OS.Environment.DirectoryPictures).AbsolutePath;
                localPath = System.IO.Path.Combine(documentsPath, localFilename);

                //Done.



            }
            catch (Exception Ex)
            {
                string LineErrorNumber = "Error line: " + Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7) + "\r\n" + "Error: " + Ex.Message;
            }
            finally
            {
                await Share.RequestAsync(new ShareFileRequest
                {
                    Title = **"Delicate info from MyAPP"**,
                    File = new ShareFile(localPath)
                });
            }
        }

需要注意的是,如果我使用另一种仅用于文本的共享方法,那么我可以毫无问题地共享它。

纯文本方法:

private async Task ShareText(string Tipo, string Titulo, string ContenidoaCompartir)
        {
            try
            {
                await Share.RequestAsync(new ShareTextRequest
                {
                    Uri = "Delicate info from MyAPP",
                    Title = Titulo, 
                    Subject = (Tipo + " de " + Titulo).ToString(),
                    Text = "MyApp - " + Tipo + " de " + Titulo + ":" + System.Environment.NewLine + ContenidoaCompartir + System.Environment.NewLine
                });
            }
            catch (Exception Ex)
            {
                string LineErrorNumber = "Error line: " + Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7) + "\r\n" + "Error: " + Ex.Message; Crashes.TrackError(Ex);
            }
        }

您可以查看下面的问题,其中显示了如何通过 whatsapp 分享文字和图片 Share image and text through Whatsapp or Facebook