Connecting to IPFS from Android Devices

Lalith Medury
Coinmonks
2 min readApr 14, 2021

--

While it’s relatively easy to connect a Web Application with an IPFS client, it gets a tad tricky to do the same from the Android SDK. In this tutorial, I’ll walk you through the setup phase, add a document to the IPFS and view its contents.

To start off, import the following gradle package:

In the app.gradle file:

When trying to implement the IPFS methods, some of them might not work as intended. One such error is:

This happens due to some methods not being available in Java Versions < 8. Switching to Java 8 compatibility might fix this issue:

Once the project dependencies are imported, sync the gradle file to save changes.

In MainActivity.java (can be any activity file), import the following packages:

Instantiating the IPFS client requires a MultiAddress parameter to be passed to the constructor:

Once you set up the client, you can add files and retrieve the hash. Calling the ipfsClient.add() method adds the file and returns the MerkleNode result:

Since IPFS is Content Addressable Decentralized File Hosting, all you need is a hash to retrieve the document. From the above code, you can observe that if everything went well, you’ll be able to find the hash in the ‘info’ tab in the Logs. The effective URL to find the document in IPFS will be:

https://ipfs.infura.io/ipfs/<document-hash>

That is it. You have successfully added contents to IPFS using an Android SDK.

--

--

Lalith Medury
Coinmonks

Undergraduate student at Vidya Jyothi Institute of Technology, Hyderabad. Interested in learning about Computer Networks and Security. A huge soccer fan.