mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
feat(cast): clicking on the notif opens specified path
This commit is contained in:
@@ -16,5 +16,12 @@
|
||||
<action android:name="androidx.media3.session.MediaSessionService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<activity
|
||||
android:name="dev.zoriya.omni.OmniCastTapActivity"
|
||||
android:exported="false"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:taskAffinity=""
|
||||
android:theme="@android:style/Theme.NoDisplay" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -26,11 +26,7 @@ class OmniCastOptionsProvider : OptionsProvider {
|
||||
.setSmallIconDrawableResId(
|
||||
androidx.media3.session.R.drawable.media3_notification_small_icon
|
||||
)
|
||||
.apply {
|
||||
context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||
?.component?.className
|
||||
?.let { setTargetActivityClassName(it) }
|
||||
}
|
||||
.setTargetActivityClassName(OmniCastTapActivity::class.java.name)
|
||||
.build()
|
||||
|
||||
val mediaOptions = CastMediaOptions.Builder()
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package dev.zoriya.omni
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.core.net.toUri
|
||||
|
||||
class OmniCastTapActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val url = getSharedPreferences(OmniPlayer.OMNI_PREFS, Context.MODE_PRIVATE)
|
||||
.getString(OmniPlayer.NOTIFICATION_URL_PREF, null)
|
||||
val intent = url
|
||||
?.let { Intent(Intent.ACTION_VIEW, it.toUri()).setPackage(packageName) }
|
||||
?: packageManager.getLaunchIntentForPackage(packageName)
|
||||
|
||||
try {
|
||||
startActivity(
|
||||
intent?.apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
}
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
android.util.Log.w("OmniPlayer", "could not open $url", e)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,12 @@ class OmniPlayer(
|
||||
|
||||
val player: Player = runOnMainThreadSync {
|
||||
castOptions?.receiverApplicationId?.let { receiverApplicationId = it }
|
||||
// the cast notification outlives the app, so OmniCastTapActivity has to find the
|
||||
// url back even when nothing of ours ran in that process yet.
|
||||
ctx.getSharedPreferences(OMNI_PREFS, Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putString(NOTIFICATION_URL_PREF, castOptions?.notificationUrl)
|
||||
.apply()
|
||||
val cc = try {
|
||||
CastContext.getSharedInstance(ctx)
|
||||
} catch (_: Throwable) {
|
||||
@@ -648,6 +654,10 @@ class OmniPlayer(
|
||||
// Receiver application id passed at runtime via OmniProvider's `cast`
|
||||
// prop; read by OmniCastOptionsProvider when the Cast SDK initializes.
|
||||
var receiverApplicationId: String? = null
|
||||
|
||||
// `cast.notificationUrl`, read back by OmniCastTapActivity.
|
||||
const val OMNI_PREFS = "dev.zoriya.omni"
|
||||
const val NOTIFICATION_URL_PREF = "notificationUrl"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user