> For the complete documentation index, see [llms.txt](https://dev-en.omnione.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-en.omnione.net/sdk-instruction-guide/untitled/android.md).

# Android

## 1. Omnilink  import and settings&#x20;

Copy arr library file in the libs folder of App-level directory (create if missing)

![](/files/-MEztgbdnOUf6tvkK1no)

After, Add arr file and additional library as below.

![](/files/-MEztp9XRB1ClhyCzr7i)

## 2. AndroidManifest.xml settings

Add Internet permission for servlet communication.

```markup
<uses-permission android:name="android.permission.INTERNET" />
```

## 3. Host, Scheme setting

```markup
<activity android:name=".MainActivity"
    android:launchMode="singleTask"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustNothing">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:scheme="your app scheme"
            android:host="your app host" />
    </intent-filter>
</activity>
```

{% hint style="info" %}

* launchMode of Activity will not operate properly, if it is not a "singleTask" on a specific browser.
* The scheme, host, and past MUST be equal to set items on RSBridge for JSP.
  {% endhint %}

{% hint style="info" %}

* scheme uses the custom scheme like "rsbsample" and Android may be able to use a known scheme such as "http", "https".
* scheme can apply more than one as shown as the above example. At this time, intent-filter may be able to create separately depending on whether the host and path.
  {% endhint %}

## 4. API

### 4.1 Create

|   CLASS   | Content                                                                                                                                                                                                  |
| :-------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  Purpose  | Creator for initial implementation                                                                                                                                                                       |
|    Use    | OmniLinkManager(this, OmniLinkListener)                                                                                                                                                                  |
| Parameter | Activity, OmniLinkListener                                                                                                                                                                               |
|   Return  | void                                                                                                                                                                                                     |
|  Example  | <p>var omniLinkManager = OmniLinkManager(this, object: OmniLinkListener { </p><p>     override fun receive(data: String) {</p><p>     }</p><p>     override fun sendFinish() {</p><p>     }</p><p>})</p> |
|    Note   | <ul><li>Creator</li></ul>                                                                                                                                                                                |

### 4.2 setPackageName

|   CLASS   | Content                                                                                                |
| :-------: | ------------------------------------------------------------------------------------------------------ |
|  Purpose  | Redirects to the market, when target App is not stored on the device                                   |
|    Use    | setPackageName(String)                                                                                 |
| Parameter | packageName                                                                                            |
|   Return  | void                                                                                                   |
|  Example  | omniLinkManager.setPackageName(“target package name”)                                                  |
|    Note   | <ul><li>Use the transmitting App</li><li>Returns the error msg when the Package is not saved</li></ul> |

### 4.3 setActivity

|   CLASS   | Content                                                |
| :-------: | ------------------------------------------------------ |
|  Purpose  | Use when the target App already exists in the Os stack |
|    Use    | setActivity(Activity)                                  |
| Parameter | activity                                               |
|   Return  | void                                                   |
|  Example  | omniLinkManager.setActivity(this)                      |
|    Note   | <ul><li>uses the target App</li></ul>                  |

### 4.4 callApp

|   CLASS   | Content                                                                       |
| :-------: | ----------------------------------------------------------------------------- |
|  Purpose  | Use when calling and forward data from the transmitting App to the target App |
|    Use    | callApp(String, String, String, String)                                       |
| Parameter | host, scheme, type, select                                                    |
|   Return  | void                                                                          |
|  Example  | omniLinkManager.callApp(this)                                                 |
|    Note   | <ul><li>Uses the transmitting App</li></ul>                                   |

### 4.5 returnResult

|   CLASS   | Content                                          |
| :-------: | ------------------------------------------------ |
|  Purpose  | Forwards the Result data to the transmitting App |
|    Use    | callApp(OmniLinkData)                            |
| Parameter | omniLinkData                                     |
|   Return  | void                                             |
|  Example  | omniLinkManager.returnResult(omniLinkData)       |
|    Note   | <ul><li>Uses the target App</li></ul>            |

### 4.6 receiveResult

|   CLASS   | Content                                                            |
| :-------: | ------------------------------------------------------------------ |
|  Purpose  | parsing the delivered data from the target app to transmitting app |
|    Use    | receiveResult(Int, Int, Intent)                                    |
| Parameter | requestCode, resultCode, intent                                    |
|   Return  | void                                                               |
|  Example  | omniLinkManager.receiveResult(requestCode, resultCode, intent)     |
|    Note   | <ul><li>Uses the transmitting App</li></ul>                        |

### 4.7 isExistPackage

|   CLASS   | Content                                                         |
| :-------: | --------------------------------------------------------------- |
|  Purpose  | Checks if an App in that package exists in the device           |
|    Use    | isExistPackage(Context, String)                                 |
| Parameter | context, packageName                                            |
|   Return  | Boolean                                                         |
|  Example  | Util.isExistPackage(context, “package name”)                    |
|    Note   | <ul><li>Uses transmitting App</li><li>Uses target App</li></ul> |

### 4.8 exit

|   CLASS   | Content                                                           |
| :-------: | ----------------------------------------------------------------- |
|  Purpose  | After exiting an App, removes the termination app in the OS stack |
|    Use    | exit(Activity)                                                    |
| Parameter | activity                                                          |
|   Return  | void                                                              |
|  Example  | Util.exit(this)                                                   |
|    Note   | <ul><li>Uses the transmitting App</li></ul>                       |

## 5. Sample source

### 5.1 MainActivity.kt (Transmitting App)

```kotlin
class MainActivity : AppCompatActivity() {
    private val mPackageName = "com.omnioneltd.receiveapp"
    private val mToAppHost = "receivehost"
    private val mToAppScheme = "receivescheme"

    private lateinit var mOmniLinkManager : OmniLinkManager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // create ToApp
        mOmniLinkManager = OmniLinkManager(this, object: OmniLinkListener {
            override fun receive(data: String) {
                // receive from app or request error code
                val resultData = OmniLinkData(data)
                if(Codes.success == resultData.code){
                    printLog("success receive : ${resultData.toJson()}")
                } else {
                    printLog("error receive : ${resultData.toJson()}")
                }
            }

            override fun sendFinish() {
                // work finish
                printLog("finish")
            }
        })

        // if does not exist response app in phone. go to market
        mOmniLinkManager.setPackageName(mPackageName)

        log.movementMethod = ScrollingMovementMethod()

        user_auth_btn.setOnClickListener { v ->
            // does check exist response app
            if(Util.isExistPackage(this@MainActivity, mPackageName)){
                pickContact()
            } else {
                printLog("does not exist $mPackageName")
            }
        }

        did_auth.setOnClickListener { v ->
            pickContact()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        // receive check
        mOmniLinkManager.receiveResult(requestCode, resultCode, data)
    }

    private fun pickContact() {
        // call app
        mOmniLinkManager.callApp(mToAppHost, mToAppScheme, Type.DID_AUTH, "select type")
    }

    fun printLog(text: String) {
        if(log.text == null || log.layout == null || log.lineCount == null){
            return
        }

        log.text = log.text.toString() + "\n" + text
        val scrollY = log.layout.getLineTop(log.lineCount) - log.height
        if (scrollY > 0) {
            log.scrollTo(0, scrollY)
        }
    }
}
```

### 5.2 MainActivity.kt (Target App)

```kotlin
class MainActivity : AppCompatActivity() {
    lateinit var mOmniLinkManager : OmniLinkManager

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)

        // it's running this app
        mOmniLinkManager.setActivity(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // create ToApp
        mOmniLinkManager = OmniLinkManager(this, getToAppListener())

        log.movementMethod = ScrollingMovementMethod()

        callback.setOnClickListener {
            // make callback message
            OmniLinkData().let {
                val code = code.text.toString()
                val msg = msg.text.toString()
                val data = data.text.toString()

                it.code = if(TextUtils.isEmpty(code)) Codes.success else code.toInt()
                it.msg = if(TextUtils.isEmpty(msg)) "success" else msg
                it.data = if(TextUtils.isEmpty(data)) "Check the information in the existing app." else data

                mOmniLinkManager.returnResult(it)
            }
        }
    }

    private fun getToAppListener(): OmniLinkListener {
        return object: OmniLinkListener {
            override fun receive(data: String) {
                // receive from app or request error code
                val resultData = OmniLinkData(data)
                if(Codes.success == resultData.code){
                    Handler().postDelayed({
                        printLog("success receive : ${resultData.toJson()}")
                    }, 1000)
                } else {
                    printLog("error receive : ${resultData.toJson()}")
                }
            }

            override fun sendFinish() {
                // work finish
                printLog("finish")
                this@MainActivity.finish()
            }
        }
    }

    fun printLog(text: String) {
        if(log.text == null || log.layout == null || log.lineCount == null){
            return
        }

        log.text = log.text.toString() + "\n" + text
        val scrollY = log.layout.getLineTop(log.lineCount) - log.height
        if (scrollY > 0) {
            log.scrollTo(0, scrollY)
        }
    }
}
```
