Last active
April 23, 2024 08:44
-
-
Save tmodoux/78c42cdd9781689cfe51c3dad6d97ee9 to your computer and use it in GitHub Desktop.
MainActivity kotlin code for twilio voice sdk integration in android app built with React native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.androidapp | |
import com.facebook.react.ReactActivity | |
import com.facebook.react.ReactActivityDelegate | |
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled | |
import com.facebook.react.defaults.DefaultReactActivityDelegate | |
import android.Manifest | |
import android.content.Intent | |
import android.os.Build | |
import android.os.Bundle | |
import android.widget.Toast | |
import com.twiliovoicereactnative.VoiceActivityProxy | |
class MainActivity : ReactActivity() { | |
private val activityProxy = VoiceActivityProxy(this) { permission -> | |
when (permission) { | |
Manifest.permission.RECORD_AUDIO -> Toast.makeText( | |
this@MainActivity, | |
"Microphone permissions needed. Please allow in your application settings.", | |
Toast.LENGTH_LONG | |
).show() | |
Manifest.permission.BLUETOOTH_CONNECT -> | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
Toast.makeText( | |
this@MainActivity, | |
"Bluetooth permissions needed. Please allow in your application settings.", | |
Toast.LENGTH_LONG | |
).show() | |
} | |
Manifest.permission.POST_NOTIFICATIONS -> | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2) { | |
Toast.makeText( | |
this@MainActivity, | |
"Notification permissions needed. Please allow in your application settings.", | |
Toast.LENGTH_LONG | |
).show() | |
} | |
} | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
activityProxy.onCreate(savedInstanceState) | |
} | |
override fun onDestroy() { | |
activityProxy.onDestroy() | |
super.onDestroy() | |
} | |
override fun onNewIntent(intent: Intent?) { | |
super.onNewIntent(intent) | |
activityProxy.onNewIntent(intent) | |
} | |
/** | |
* Returns the name of the main component registered from JavaScript. This is used to schedule | |
* rendering of the component. | |
*/ | |
override fun getMainComponentName(): String = "REPLACE_WITH_YOUR_APP_NAME" | |
/** | |
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] | |
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled] | |
*/ | |
override fun createReactActivityDelegate(): ReactActivityDelegate = | |
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment