Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Notification
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
Expand All @@ -20,7 +19,6 @@ import java.io.File
import java.net.URL

private const val TAG = "LiveUpdatesManager"
private const val EXPO_MODULE_SCHEME_KEY = "expo.modules.scheme"
private const val DEFAULT_MAX_PROGRESS = 100

object NotificationActionExtra {
Expand Down Expand Up @@ -258,10 +256,19 @@ class LiveUpdatesManager(private val context: Context) {

clickIntent?.apply {
action = Intent.ACTION_VIEW

val scheme = getScheme(context)

config?.deepLinkUrl?.let { deepLink ->
val scheme = getScheme(context)
data = "$scheme://${deepLink.removePrefix("/")}".toUri()
scheme?.let { data = "$scheme://${deepLink.removePrefix("/")}".toUri() }
?: run {
Log.w(
TAG,
"deepLinkUrl property ignored. Please configure withChannelConfig plugin with scheme in app.config.ts to enable managing Live Update deeplinks.",
)
}
}

putExtra(NotificationActionExtra.NOTIFICATION_ACTION, NotificationAction.CLICKED)
putExtra(NotificationActionExtra.NOTIFICATION_ID, notificationId)
}
Expand All @@ -275,11 +282,4 @@ class LiveUpdatesManager(private val context: Context) {
)
notificationBuilder.setContentIntent(clickPendingIntent)
}

fun getScheme(context: Context): String {
val applicationInfo =
context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
return applicationInfo.metaData?.getString(EXPO_MODULE_SCHEME_KEY)
?: throw IllegalStateException("$EXPO_MODULE_SCHEME_KEY not found in AndroidManifest.xml")
}
}
24 changes: 16 additions & 8 deletions android/src/main/java/expo/modules/liveupdates/ManifestHelpers.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
package expo.modules.liveupdates

import android.content.Context
import android.content.pm.PackageManager
import android.util.Log

private const val CHANNEL_ID_KEY = "expo.modules.liveupdates.channelId"
private const val CHANNEL_NAME_KEY = "expo.modules.liveupdates.channelName"
private const val EXPO_MODULE_SCHEME_KEY = "expo.modules.scheme"
private const val TAG = "ManifestHelpers"

private fun getMetadataFromManifest(context: Context, key: String): String {
private fun getMetadataFromManifest(context: Context, key: String): String? {
val packageManager = context.packageManager
val packageInfo =
packageManager.getApplicationInfo(
context.packageName,
android.content.pm.PackageManager.GET_META_DATA,
)
packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
return packageInfo.metaData?.getString(key)
}

private fun getRequiredMetadataFromManifest(context: Context, key: String): String {
return getMetadataFromManifest(context, key)
?: run {
Log.w("ManifestHelpers", "Failed to read $key from manifest")
Log.w(TAG, "Failed to read $key from manifest.")
throw RuntimeException(
"ExpoLiveUpdatesModule: $key is required. Please configure withChannelConfig plugin with ${key.split(".").last()} in app.config.ts"
)
}
}

fun getChannelId(context: Context): String {
return getMetadataFromManifest(context, CHANNEL_ID_KEY)
return getRequiredMetadataFromManifest(context, CHANNEL_ID_KEY)
}

fun getChannelName(context: Context): String {
return getMetadataFromManifest(context, CHANNEL_NAME_KEY)
return getRequiredMetadataFromManifest(context, CHANNEL_NAME_KEY)
}

fun getScheme(context: Context): String? {
return getMetadataFromManifest(context, EXPO_MODULE_SCHEME_KEY)
}