Skip to content

dragonkorn/android-test-library

Repository files navigation

AppConnectSDK Library

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.

Installation

To use the AppConnectSDK library in your Android project, follow these steps:

  1. 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")
  1. 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>
  1. 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>

Usage

Here's how you can use the AppConnectSDK library to communicate between two applications:

Example: Application A sending data to Application B

val a2bChannel = AppConnectSDK.createChannel(
  this, 
  "A_CONTENT_PROVIDER_AUTHORITY", 
  "B_CONTENT_PROVIDER_AUTHORITY", 
  ChannelConfiguration(commitOnRead = false)
)

a2bChannel.send("Hello Profita", getExpiry(minute = 30))

Example: Application B reading data from Application A

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()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages