gpt4 book ai didi

android - intent.setType ("application/pdf") 允许选择任何文件

转载 作者:行者123 更新时间:2023-11-29 18:36:46 24 4
gpt4 key购买 nike

我正在制作一个应用程序,我想在其中提供上传 pdf 文件的选项。我已经编写了这段代码,但它允许选择任何类型的文档。我只想允许选择pdf文件。我的目标是 API 级别 28。

 case 2:
Intent pickPdf = new Intent(Intent.ACTION_GET_CONTENT);
pickPdf.setType("application/pdf");
pickPdf.addCategory(Intent.CATEGORY_OPENABLE);
myBundle.putString("type",type);
try {
startActivityForResult(Intent.createChooser(pickPdf, "Select a File to Upload"),103);
} catch (ActivityNotFoundException e) {
Toast.makeText(GuarantorDocsupload.this, "Please Install a File Manager",Toast.LENGTH_SHORT).show();
}
break;

最佳答案

这对我有用。

private static final int STORAGE_PERMISSION_CODE = 123;

Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

try {
startActivityForResult(Intent.createChooser(intent, "Select Your .pdf File"), PICK_PDF_REQUEST);
} catch (ActivityNotFoundException e) {
Toast.makeText(GuarantorDocsupload.this, "Please Install a File Manager",Toast.LENGTH_SHORT).show();
}

也许这会对你有所帮助。

关于android - intent.setType ("application/pdf") 允许选择任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54002833/

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