Get all pdf files in device

To get a list of all pdf files in device, follow the steps given below.

1. Create a new Sketchware project.

2. In main.xml add a ListView listview1 and a ProgressBar progressbar1 inside a LinearV linear1.

3. Create a CustomView mycustom.xml. Select it as CustomView for listview1.

4. In mycustom.xml add a TextView textview1.

5. In the event onCreate, call the AsyncTask GetAllTask using following code:
(new GetAllTask()).execute();
6. Create two number variables n and r, and two String variables folder and folderName.

7. Create two List String folderList and fileList, and a List Map all_pdfs.

8. Create three more blocks:
i. extra
ii. getFileList in [filePath]
iii. searchFolders

9. In the More Block extra, use codes and blocks as shown below.

Here we perform following actions:
i. Define a new class AsyncTask GetAllTask.
}

private class GetAllTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {

ii. In onPreExecute, make progressbar1 VISIBLE.

iii. Use following code:
}

@Override
protected Void doInBackground(Void... path) {

iv. In doInBackground method, set number to 0, clear all_pdfs, clear folderList.
Then use getFileList in [filePath] block to get path of all pdfs from external storage directory.

v. Use following code for onProgressUpdate and onPostExecute methods.
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
}
@Override
protected void onPostExecute(Void param){

vi. In onPostExecute, make progressbar1 GONE. Display ListMap all_pdfs in listview1. Toast number of files added.

vii. Use following code:
}

10. Define More Block getFileList in [filePath]  using blocks as shown in image below.

11. Define More Block searchFolders using blocks as shown in image below.


12. In onBindCustomView use blocks to set the text of textview1 by getting file name from List Map all_pdfs.

13. Save and Run the project.

* The same blocks can be used to get all images or all music files by changing .pdf to .jpg or .mp3 respectively, in the getFileList in filePath block.

Comments

  1. But how we make any pdf file in list view readable..?

    ReplyDelete

Post a Comment

Popular posts from this blog

Create Music Player app in Sketchware

A Flash Light App in Sketchware

Admob rewarded video Ads in Sketchware

Firebase auth in Sketchware for Login Activity

Simple car racing android game in Sketchware