用于Android中的Cast连接的广播接收器 [英] Broadcast Receiver for Cast Connectivity in Android

查看:130
本文介绍了用于Android中的Cast连接的广播接收器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想使用Google Cast代码从我的应用程序连接设备,而只需要检查手机是否已连接到任何Cast设备。

I don't want to use google cast code to connect devices from my app but needed to just check whether the phone is connected to any cast Device.

我们可以为此检查获得任何接收者/收听者吗?

Do we get any Receiver/listener for this check?

谢谢!

编辑:
我试图通过以下方式获取演员表状态:克里斯,

I have tried to get Cast State as following as mentioned by Chris,


  1. 在清单中添加以下内容




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





  1. 创建CastOptionProvider类




public class CastOptionsProvider implements OptionsProvider {
    @Override
    public CastOptions getCastOptions(Context context) {
        return new CastOptions.Builder()
                .build();
    }
    @Override
    public List<SessionProvider> getAdditionalSessionProviders(Context context) {
        return null;
    }
}





  1. 在MainActivity中读取状态,




CastContext mCastContext = CastContext。 getSharedInstance(context);
if(mCastContext!= null){
int x = mCastContext.getCastState();

CastContext mCastContext = CastContext.getSharedInstance(context); if (mCastContext != null) { int x = mCastContext.getCastState();

    }


此处x的值始终为 1,即没有可用的设备,即使手机已连接到任何Miracast设备。

Here Value of x is always "1" i.e. no Devices Available, eventhough the phone is connected to any Miracast Device.

推荐答案

CastContext:

CastContext:

https://developers.google .com / android / reference / com / google / android / gms / cast / framework / CastContext

getCastState 会告诉您是否已连接或可以调用 addCastStateListener 来检测状态何时更改。

getCastState will tell you whether you're connected or you can call addCastStateListener to detect when the state changes.

这篇关于用于Android中的Cast连接的广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆