Using PDF Pinner To Pin PDFs to Android Home Screen

Paras Singh Sidhu
HackerBay
Published in
3 min readJan 23, 2018

--

This is a story (technical part included) about one of my recent android application. As a student, I need to access PDF files frequently. Every time I need to so, I need to open File Explorer or Adobe Acrobat and find the desired file to open it. Uff… very effort-some 😜 Being a programmer, we just love to automate our tasks. So I thought of putting the files straight to the home screen. But how will I do it, I thought? A quick Google search 🌐 and almighty StackOverflow showed that it’s easy to pin the files to home screen in Android using Intent. So as soon as my semester exams finished, I gone after this task. It was fun designing and coding the app and here’s how it looks:

Development

The design part was easy and I used simple styled buttons, powerful RecyclerView and some radio buttons. The only thing here is that some design elements behave differently in Android Oreo due to its restrictive behaviour. More on it in later section.

Since the app should pin PDF files to home screen, it should be able to pin multiple files at once. To choose files, I used Android-FilePicker library which provides user-friendly interface to select files of desired extension. Once user chooses the files, file name and path are passed to an ArrayList which is passed to our RecyclerViewAdapter to inflate the list in the main UI.

In main user interface, there’s an option to edit shortcut name. This option actually edits the name in ArrayList. Then user can choose from any of two icons and press Pin File(s) button to finish the task… wait not yet… 😐

Android Oreo Support

If you’re not on Android 8.0 or above, the files should have been pinned to home screen with a success message. But what if OS is Oreo or 8.0+? Google introduced a new ShortcutManager API in Oreo to handle pinning of any type of shortcut to home screen. This is done to ensure fake/spam apps don’t pin unwanted icons to home screen. But this new API comes with a restriction that you can’t pin multiple files in one go. You have to pin them one by one.

As I wrote before that some design elements will behave differently in Oreo, upon pressing “Pin File(s)” button, a system dialog will appear asking for permission.

Once you add this shortcut, PDF Pinner will ask you to “Pin Next File” if you have multiple files selected. You can press that to progress similarly. You can see the following code on how to use ShortcutManager API:

Wrap Up

PDF Pinner is available to download in Play Store. It’s one of my first open-source project and you can see full code in my Github repo:

If you have some suggestions, you can create an issue in repo or make a pull request. I will be happy to further improve PDF Pinner 😃

--

--