Android 当应用程序发送到后台时,ChromeCast通知不可见

Android 当应用程序发送到后台时,ChromeCast通知不可见,android,chromecast,google-cast,Android,Chromecast,Google Cast,我想从我的应用程序中显示chromecast通知和锁屏。目前我正在使用android。根据应用程序类中初始化的示例应用程序CastConfiguration和VideoCastManager String applicationId = getString(R.string.app_id); CastConfiguration options = new CastConfiguration.Builder(applicationId) .enableAutoReconne

我想从我的应用程序中显示chromecast通知和锁屏。目前我正在使用android。根据应用程序类中初始化的示例应用程序
CastConfiguration
VideoCastManager

String applicationId = getString(R.string.app_id);
CastConfiguration options = new CastConfiguration.Builder(applicationId)
            .enableAutoReconnect()
            .enableDebug()
            .enableLockScreen()
            .enableNotification()
            .enableWifiReconnection()
            .setCastControllerImmersive(true)
            .setLaunchOptions(false, Locale.getDefault())
            .addNamespace(NAMESPACE)
            .setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_DISABLED)
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true)
            .build();

VideoCastManager.initialize(this, options);
AndroidManifest.xml

    <receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" />

    <service android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" />

    <service android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService" />

注意:我正在使用CustomReceiver进行强制转换。

首先,将清单中通知服务的xml描述更改为CCL文档中提到的描述,或者从CastVideos-android-v2中查找。其次,如果您运行示例应用程序(CastVideos-android-v2),一切正常吗?@AliNaddaf Manifest xml现在已更改(请参阅相关编辑)。示例应用程序在我用于我的应用程序的同一设备中运行良好。是否可能您的应用程序(在Android中)已禁用通知?如果您是从源代码(而不是aar)使用CCL,那么您应该能够调试您这边的问题,以查看发生了什么。@AliNaddaf从日志中,我发现getRemoteMediaInformation()总是空的。我使用的是自定义接收器,因此在我的主要活动中初始化了MediaInfo(如有问题所述)。
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_TITLE, mEpisode.getmName());
    movieMetadata.addImage(new WebImage(Uri.parse(mEpisode.getmBannerImageUrl())));
    movieMetadata.addImage(new WebImage(Uri.parse(mEpisode.getmBannerSmallImageUrl())));

    try {
        MediaInfo mediaInfo = new MediaInfo.Builder(mEpisode.getmName() + ":" + mEpisode.getId())
                .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                .setContentType("video/mp4")
                .setMetadata(movieMetadata)
                .setCustomData(new JSONObject(customMessage))
                .build();

        mVideoManager.loadMedia(mediaInfo, false, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }