繁体   English   中英

如何使用 url 启动器将文件发送到 whatsapp 中的特定联系人 - Flutter

[英]How to send a file to specific contact in whatsapp using url launcher - Flutter

我们可以直接向特定联系人发送短信,但我想使用 url 启动器向 whatsapp 联系人发送文件。 如何在 flutter 中实现这一点。

以下是我仅发送消息的代码。

String message = "sample text";
String androidURL = "https://wa.me/917390123456/?text=${Uri.parse(message)}";

if(await canLaunchUrl(Uri.parse(URL))){
    await launchUrl(Uri.parse(URL),mode: LaunchMode.externalApplication);
}

这适用于发送短信。 如何使用相同的方式发送文件。 有人可以帮忙吗。

要发送文件,您可以使用whatsapp://send?file=<file_url>" URL 方案。要发送图像,您可以使用"whatsapp://send?text=&file=<file_url>" 和文件格式应为 jpeg 或 png 格式。

import 'package:url_launcher/url_launcher.dart';

// ...

void _sendFileToWhatsApp() async {
  var phoneNumber = "917390123456";
  var fileUrl = "https://example.com/file.pdf"; // Replace with the URL of the file you want to send
  var url = "whatsapp://send?phone=$phoneNumber&file=$fileUrl";

  if (await canLaunchUrl(url)) {
    await launchUrl(url);
  }
}

在这里检查。 共享图像或文件 _image1.path 包含共享到 whatsapp 的文件的路径。 在这里查看whatsapp_share

Future<void> shareFile() async {
await WhatsappShare.shareFile(
  text: 'Whatsapp share text',
  phone: '911234567890',
  filePath: [_image1.path, _image2.path],
);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM