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

Android TV App isn't opening #109

Open playtvgo opened 3 years ago

playtvgo commented 3 years ago

I want to open android tv app when casting from sender app , but it always opening the web receiver . I followed this codelab Cast Connect with ATV App and this codelab for Cast-enable an Android app , After that


Sender Option Provider class
```java

    public class CastOptionProvider implements OptionsProvider {
        @Override
        public CastOptions getCastOptions(Context context) {
            CastOptions customCastOptions = Casty.customCastOptions;
            if (customCastOptions == null) {
                List<String> buttonActions = createButtonActions();
                int[] compatButtonAction = {1, 3};

                NotificationOptions notificationOptions = new NotificationOptions.Builder()
                        .setActions(buttonActions, compatButtonAction)
                        .setTargetActivityClassName(ExpandedControlsActivity.class.getName())
                        .build();

                CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
                        .setNotificationOptions(notificationOptions)
                        .setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
                        .build();
                LaunchOptions launchOptions = new LaunchOptions.Builder()
                        .setRelaunchIfRunning(true)
                        .setAndroidReceiverCompatible(true).build();

                return new CastOptions.Builder()
                        .setReceiverApplicationId(Casty.receiverId)
                        .setCastMediaOptions(mediaOptions)
                        .setLaunchOptions(launchOptions)
                        .build();
            } else {
                return customCastOptions;
            }
        }

        private List<String> createButtonActions() {
            return Arrays.asList(MediaIntentReceiver.ACTION_REWIND,
                    MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK,
                    MediaIntentReceiver.ACTION_FORWARD,
                    MediaIntentReceiver.ACTION_STOP_CASTING);
        }

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

Receiver AndroidManifest.xml


    <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

        <uses-feature
            android:name="android.hardware.touchscreen"
            android:required="false" />
        <uses-feature
            android:name="android.software.leanback"
            android:required="true" />

        <application
            android:name=".JmxApplication"
            android:allowBackup="true"
            android:appComponentFactory="androidx.core.app.CoreComponentFactory"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:networkSecurityConfig="@xml/network_security_config"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.JMXPlayerCast">

            <meta-data
                android:name="com.google.android.gms.cast.tv.RECEIVER_OPTIONS_PROVIDER_CLASS_NAME"
                android:value="com.stream.jmxplayercast.CastReceiverOptionsProvider" />

            <activity
                android:name=".ui.MainActivity"
                android:banner="@drawable/main_logo"
                android:label="@string/app_name"
                android:launchMode="singleTask"
                android:logo="@drawable/circle_cropped_logo"
                android:screenOrientation="landscape">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
                    <category android:name="android.intent.category.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>
            </activity>

            <activity
                android:name=".ui.PlayerActivity"
                android:exported="true"
                android:launchMode="singleTask">
                <intent-filter>
                    <action android:name="com.google.android.gms.cast.tv.action.LOAD" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>

                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />

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

                    <data android:scheme="http" />
                    <data android:scheme="https" />
                    <data android:mimeType="video/*" />
                    <data android:mimeType="application/*" />
                </intent-filter>
            </activity>

        </application>

ReceiverOptionProver class is the vanilla codelab's option provider. What have I done wrong and how to fix this .. Thanks in Advance

jtromo commented 3 years ago

Hi,

Have you gone through our Android TV receiver troubleshooting guide? https://developers.google.com/cast/docs/android_tv_receiver/troubleshooting

To confirm, you are not using a LaunchRequestChecker for your Android TV app? Are you seeing any errors such as APP_NOT_INSTALLED_BY_WHITELISTED_INSTALLER or INSTALLER_NOT_WHITELISTED?

nipunkraj commented 2 years ago

I am also facing the same issue and i logcat i am seeing App failed to launch. Error: APP_NOT_INSTALLED_BY_WHITELISTED_INSTALLER 2022-04-29 15:46:59.190 4572-4572/? E/cr_CastToNative: Warg launch failed (INSTALLER_NOT_WHITELISTED).

But i have already registered the cast serial no..