无法在 Android Studio 中通过 Whatsapp Intent 发送 pdf 文件。
Intent whatsappIntent =new Intent(Intent.ACTION_SEND,Uri.parse(
"https://api.whatsapp.com/send?phone=+919999999999&text=This is a Demo Message"));
whatsappIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
whatsappIntent.setType("application/pdf");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(whatsappIntent);
这是Android代码,但它不起作用。 我只能发送消息,但不能发送 pdf 文件。
意图whatsappIntent = new Intent(Intent.ACTION_SEND); WhatsappIntent.setType(“应用程序/pdf”); WhatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath)); // 将 filePath 替换为 PDF 文件的路径 WhatsappIntent.setPackage(“com.whatsapp”); // 设置 WhatsApp 包名称以确保它在 WhatsApp 中打开
startActivity(Intent.createChooser(whatsappIntent, "通过...发送 PDF"));
确保将“file://”+ filePath 替换为 PDF 文件的实际文件路径。通过将包设置为“com.whatsapp”,您可以确保意图明确指向 WhatsApp。