The AppConnectSDK is a library designed to facilitate communication between Android applications using ContentProviders. It allows applications to securely exchange data with each other, providing a seamless integration experience.
To use the AppConnectSDK library in your Android project, follow these steps:
- Clone the library to your local machine and add the library as a dependency in your build.gradle file:
-
Add the library module to your
settings.gradle
file:project(":appConnectSdk").projectDir = file("$rootDir/../TestLibrary/AppConnectSdk")
-
Include the library module in your app's build.gradle file:
implementation project(":AppConnectSdk")
- Add permissions and provider configurations to your
AndroidManifest.xml
file:
<permission
android:name="${applicationIdA}.permission.APP_CONNECT_SDK"
android:protectionLevel="signature|knownSigner"
android:knownCerts="@array/known_certs"
/>
<uses-permission android:name="${applicationIdB}.permission.APP_CONNECT_SDK"/>
<application
...
>
<provider
android:name="com.example.appconnectsdk.SharedStorageProvider"
android:authorities="com.appA.provider"
android:readPermission="${applicationIdA}.permission.APP_CONNECT_SDK"
android:enabled="true"
android:exported="true"
>
<meta-data
android:name="content_provider_authority"
android:value="com.appA.provider" />
</provider>
- Add the certificate hashcodes of allowed applications to your
res/values/strings.xml
file:
<string-array name="known_certs">
<item>AAABBBBCCCCDDDDEEEEEEFFFFF111122222233333444445555566666</item>
<item>HASH2</item>
<item>HASH3</item>
</string-array>
Here's how you can use the AppConnectSDK library to communicate between two applications:
val a2bChannel = AppConnectSDK.createChannel(
this,
"A_CONTENT_PROVIDER_AUTHORITY",
"B_CONTENT_PROVIDER_AUTHORITY",
ChannelConfiguration(commitOnRead = false)
)
a2bChannel.send("Hello Profita", getExpiry(minute = 30))
val b2aChannel = AppConnectSDK.createChannel(
this,
"B_CONTENT_PROVIDER_AUTHORITY",
"A_CONTENT_PROVIDER_AUTHORITY",
ChannelConfiguration(commitOnRead = false)
)
var message = b2aChannel.read()
println("Message: $message")
b2aChannel.commit()