googlecast / CastVideos-android

Reference Android Sender w/ Framework API: CastVideos-android application shows how to cast videos from an Android device that is fully compliant with the Cast Design Checklist.
Apache License 2.0
345 stars 183 forks source link

Cast receiver app not launching on android 11 for the first time when tv starts #132

Open shubhamrb opened 1 year ago

shubhamrb commented 1 year ago

### NOTE: This problem is happening on android 11 or higher android tv only when i first time start the tv or the tv in screensaver/sleep mode instead it opens the fallback url on web receiver

Sender Option provider

public class CustomCastOptionsProvider implements OptionsProvider {

@Override
public CastOptions getCastOptions(Context context) {
    List<String> supportedNamespaces = new ArrayList<>();
    supportedNamespaces.add(context.getString(R.string.custom_namespace));
    LaunchOptions launchOptions = new LaunchOptions.Builder()
            .setAndroidReceiverCompatible(true)
            .build();
    return new CastOptions.Builder()
            .setReceiverApplicationId(context.getString(R.string.cast_application_id))
            .setSupportedNamespaces(supportedNamespaces)
            .setLaunchOptions(launchOptions)
            .build();
}

@Override
public java.util.List<SessionProvider> getAdditionalSessionProviders(Context context) {
    return null;
}

}

Sender AndroidManifest.xml

<meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="com.frenzee.app.CustomCastOptionsProvider" />

Sender start session

castContext.getSessionManager().endCurrentSession(true); Intent castIntent = new Intent(); castIntent.putExtra("CAST_INTENT_TO_CAST_ROUTE_ID_KEY", route.getId()); castIntent.putExtra("CAST_INTENT_TO_CAST_DEVICE_NAME_KEY", route.getName()); castIntent.putExtra("CAST_INTENT_TO_CAST_NO_TOAST_KEY", false); castContext.getSessionManager().startSession(castIntent);

Receiver options provider

public class MyReceiverOptionsProvider implements ReceiverOptionsProvider {

@Override
public CastReceiverOptions getOptions(Context context) {
    List<String> supportedNamespaces = new ArrayList<>();
    supportedNamespaces.add(context.getString(R.string.custom_namespace));
    return new CastReceiverOptions.Builder(context)
            .setCustomNamespaces(supportedNamespaces)
            .setCastAppId(context.getString(R.string.cast_application_id))
            .build();
}

}

receiver AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
<uses-permission android:name="android.permission.READ_EPG_DATA" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />
<uses-feature
    android:name="android.hardware.faketouch"
    android:required="false" />
<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.nfc"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.gps"
    android:required="false" />
<uses-feature
    android:name="android.hardware.microphone"
    android:required="false" />
<uses-feature
    android:name="android.hardware.sensor"
    android:required="false" />
<uses-feature
    android:name="android.hardware.wifi"
    android:required="false" />
<uses-feature
    android:name="android.hardware.dpad"
    android:required="false" />
<uses-feature
    android:name="android.software.leanback"
    android:required="true" />

<application
    android:name=".FrenziApplication"
    android:allowBackup="true"
    android:banner="@mipmap/ic_banner_foreground"
    android:icon="@mipmap/ic_banner_foreground"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.Frenzi">

    <activity
        android:name=".activity.FirstActivity"
        android:configChanges="keyboard|keyboardHidden|navigation"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.gms.cast.tv.action.LAUNCH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.gms.cast.tv.action.LOAD" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".activity.WelcomeActivity"
        android:configChanges="keyboard|keyboardHidden|navigation"
        android:exported="true">
        <intent-filter
            android:autoVerify="true"
            tools:targetApi="m">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="https" />
            <data android:host="www.myfrenzi.com" />
            <data android:pathPattern=".*" />
            <data android:scheme="https" />
            <data android:host="myfrenzi.com" />
            <data android:pathPattern=".*" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.gms.cast.tv.action.LOAD" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activity.LoginActivity"
        android:exported="false"
        android:windowSoftInputMode="adjustPan" />

    <activity
        android:name=".activity.NavigationActivity"
        android:exported="false" />
    <activity
        android:name=".activity.MainActivity"
        android:exported="false" />

    <meta-data
        android:name="com.google.android.gms.cast.tv.RECEIVER_OPTIONS_PROVIDER_CLASS_NAME"
        android:value="com.frenzi.tv.MyReceiverOptionsProvider" />
</application>