简体   繁体   English

在Android设备上访问SD卡上的PDF文件

[英]Accessing PDF files on SD card on Android Device

I am currently developing an app for android which would allow a User to Upload a PDF file from their SD card to the servers. 我目前正在为Android开发一个应用程序,该应用程序允许用户将PDF文件从其SD卡上传到服务器。 I've looking at a tutorial to upload an Image to a server to understand the technical aspects of uploading a file. 我正在看一个将图像上载到服务器的教程,以了解上载文件的技术方面。

Intent pickImageIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickImageIntent, REQUEST_PICK_IMAGE);

I was looking at this and wondering how I would edit this code so the user could access the SD card and select a PDF file rather that the media store gallery? 我正在查看此内容,并且想知道如何编辑此代码,以便用户可以访问SD卡并选择PDF文件,而不是媒体存储库?

You'll have to create an Intent like: 您必须创建一个类似的Intent

Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select PDF"), REQUEST_PICK_PDF);

This will allow the user to select any type of file so you'll have to check the extension in onActivityResult(...) and proceed accordingly. 这将允许用户选择任何类型的文件,因此您必须检查onActivityResult(...)的扩展名并进行相应的操作。

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

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