gpt4 book ai didi

android - 如何在 android 中通过 whatsapp 共享 pdf 和文本?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:41 25 4
gpt4 key购买 nike

我尝试使用以下代码,但它没有附加 pdf 文件。

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");
if (isOnlyWhatsApp) {
sendIntent.setPackage("com.whatsapp");

}

Uri uri = Uri.fromFile(attachment);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
activity.startActivity(sendIntent);

最佳答案

我遇到了这个问题,我试图从 Assets 文件夹中打开一个 pdf 文件但我没有工作,但是当我尝试从下载文件夹中打开时(例如),它确实有效,这是一个例子:

File outputFile = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "example.pdf");
Uri uri = Uri.fromFile(outputFile);

Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");

activity.startActivity(share);

关于android - 如何在 android 中通过 whatsapp 共享 pdf 和文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39522482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com