Android Quickstart
Quickstart: Implementing Particle Auth within Android Applications
Particle Auth, responsible for driving standalone social logins leading to MPC-secured accounts, has rich support for Android (Kotlin). Introducing Web2-like onboarding into your mobile application with Particle Auth only takes a few minutes.
Below, you’ll find everything you need to get started, from beginning to end.
For complete documentation covering the implementation of Particle Auth on Android in more depth, head over to the Android SDK reference.
Before we begin installing and configuring the SDK, you’ll need a project that meets the prerequisites listed below (otherwise you may face compatability issues).
Prerequisites
- minSdkVersion 23 or higher.
- compileSdkVersion, targetSdkVersion 34 or higher.
- JavaVersion 17.
- Jetpack (AndroidX).
- Android Gradle Plugin Version 8.5.1 or higher.
- Gradle Version 8.9 or higher.
Configuring the Particle dashboard
Finally, before jumping into the SDKs themselves, you’ll need to prepare three key values from the Particle dashboard: your project ID, client key, and app ID. These keys will authenticate your instance of Particle Auth.
To retrieve them, follow the instructions below.
For more information on the Particle dashboard, take a look at this video or visit the dashboard quickstart.
Configuring settings.gradle
We’ll be using Maven to install Particle Auth; as such, ensure your settings.gradle
file looks similar to the example shown below.
Configuring build.gradle
You’re now ready to establish your dependencies and insert the previously retrieved keys to authenticate the SDK, this will be handled through your build.gradle
file. The areas in which you’ll need to place these keys have been noted in the snippet below.
Additionally, within dependencies
, you’ll need to (at a minimum) install the following:
network.particle:connect
network.particle:connect-auth-core-adapter
network.particle:wallet-service
As a result, your build.gradle
file should look similar to the following:
Configuring AndroidManifest.xml
Finally, before initializing and utilizing Particle Auth directly, you’ll additionally need configure your AndroidManifest.xml
file, ensuring your project keys are placed accordingly (handled through the previously established environment variables through build.gradle
).
Below is an example of what your AndroidManifest.xml
should resemble.
Initialize Particle Auth
You’re now ready to initialize and begin using Particle Auth. Initialization can be done in one line, simply by calling init
on ParticleNetwork
. init
takes the following parameters:
application
(this
), which represents the underlying Android application.env
, eitherEnv.DEV
,Env.PRODUCTION
, orEnv.STAGING
; this alters the information logged when using Particle Auth.chain
, aChainInfo
object representing the primary chain you intend to use (such asChainInfo.Ethereum
,ChainInfo.Polygon
).
The following snippet is an example of this.
Facilitating social login
With Particle Auth initialized, you can now facilitate social logins (creation or entry into a corresponding MPC-secured account) through AuthCore.connect
. Simply, this method requires:
socialType
, the specific social login you’re facilitating (this should be aSocialLoginType
object, such asSocialLoginType.GOOGLE
).- Additionally, you’ll need a callback function to handle a successful or failed login.
Upon calling, the user will undergo authentication through the service specified through SocialLoginType
; upon returning from this process, their account will be loaded and your application can handle next steps accordingly (through the callback function).
Examples of Utilization
Retrieve Account Information
With a user logged in, you can retrieve information about their account (such as their address or the details relating to the chosen method; for example, the email attached to their Google account).
To retrieve an object containing a large amount of general information, call AuthCore.getUserInfo
. This method will return numerous attributes based upon the login method they chose; for a full list of included properties, head over to the getUserInfo
API reference.
AuthCore.getUserInfo
will include a wallets
object with their address present; although an address can also be retrieved through AuthCore.evm.getAddress
, or if Solana is being used, AuthCore.solana.getAddress
.
Sending a Transaction
Additionally, sending a transaction is relatively straightforward; ParticleNetwork
has a built-in transaction construction method, createTransaction
, which simply takes a from
, to
, and value
field (optionally, data
can be used for contract interaction) and returns a transaction object to be used with AuthCore.evm.sendTransaction
.
Below is an example of this flow.
Was this page helpful?