AppId setup;

Namespaces setup;
This commit is contained in:
gianlucaparadise 2019-11-13 06:08:48 +01:00
parent b4b8eb258a
commit cb52317399
7 changed files with 39 additions and 13 deletions

View file

@ -44,7 +44,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.google.android.gms:play-services-cast-framework:17.1.0" api "com.google.android.gms:play-services-cast-framework:17.1.0"
// Lifecycle // Lifecycle
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

View file

@ -1,9 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest package="com.gianlucaparadise.flutter_cast_framework">
package="com.gianlucaparadise.flutter_cast_framework">
<application>
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.gianlucaparadise.flutter_cast_framework.cast.CastOptionsProvider" />
</application>
</manifest> </manifest>

View file

@ -0,0 +1,22 @@
package com.gianlucaparadise.flutter_cast_framework.cast
import android.content.Context
import com.google.android.gms.cast.framework.CastOptions
import com.google.android.gms.cast.framework.OptionsProvider
import com.google.android.gms.cast.framework.SessionProvider
/**
* This is here to be used as an example
*/
class DefaultCastOptionsProvider : OptionsProvider {
override fun getCastOptions(context: Context): CastOptions {
return CastOptions.Builder()
.setReceiverApplicationId("4F8B3483")
.build()
}
override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
return null
}
}

View file

@ -29,5 +29,10 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.gianlucaparadise.flutter_cast_framework_example.CastOptionsProvider" />
</application> </application>
</manifest> </manifest>

View file

@ -1,4 +1,4 @@
package com.gianlucaparadise.flutter_cast_framework.cast package com.gianlucaparadise.flutter_cast_framework_example
import android.content.Context import android.content.Context
import com.google.android.gms.cast.framework.CastOptions import com.google.android.gms.cast.framework.CastOptions

View file

@ -18,9 +18,12 @@ class _MyAppState extends State<MyApp> {
final textMessageController = TextEditingController(); final textMessageController = TextEditingController();
final String castNamespace = 'urn:x-cast:cast-your-instructions';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
FlutterCastFramework.namespaces = [castNamespace];
FlutterCastFramework.castContext.state.addListener(_onCastStateChanged); FlutterCastFramework.castContext.state.addListener(_onCastStateChanged);
FlutterCastFramework.castContext.sessionManager.state FlutterCastFramework.castContext.sessionManager.state
.addListener(_onSessionStateChanged); .addListener(_onSessionStateChanged);
@ -60,7 +63,7 @@ class _MyAppState extends State<MyApp> {
void _onSendMessage() { void _onSendMessage() {
String message = this.textMessageController.text; String message = this.textMessageController.text;
FlutterCastFramework.castContext.sessionManager FlutterCastFramework.castContext.sessionManager
.sendMessage('urn:x-cast:cast-your-instructions', message); .sendMessage(castNamespace, message);
} }
@override @override
@ -79,7 +82,7 @@ class _MyAppState extends State<MyApp> {
style: Theme.of(context).textTheme.title, style: Theme.of(context).textTheme.title,
), ),
Text('Cast State: $_castState'), Text('Cast State: $_castState'),
Text('Cast State: $_sessionState'), Text('Session State: $_sessionState'),
Text( Text(
'Message', 'Message',
style: Theme.of(context).textTheme.title, style: Theme.of(context).textTheme.title,

View file

@ -7,6 +7,9 @@ class FlutterCastFramework {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('flutter_cast_framework'); const MethodChannel('flutter_cast_framework');
/// List of namespaces to listen for custom messages
static List<String> namespaces = [];
static bool _isInitiated = false; static bool _isInitiated = false;
static _init() { static _init() {
@ -33,7 +36,7 @@ class FlutterCastFramework {
break; break;
case PlatformMethodNames.getSessionMessageNamespaces: case PlatformMethodNames.getSessionMessageNamespaces:
return ["urn:x-cast:cast-your-instructions"]; return namespaces;
case PlatformMethodNames.onMessageReceived: case PlatformMethodNames.onMessageReceived:
castContext.sessionManager.platformOnMessageReceived(arguments); castContext.sessionManager.platformOnMessageReceived(arguments);