Broadcast Receiver for Cast Connectivity in Android

邮差的信 提交于 2019-12-08 09:12:46

问题


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?

Thanks!

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

  1. Add following in Manifest
<meta-data
            android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
            android:value=".CastOptionsProvider" />
  1. Create CastOptionProvider Class
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. Reading state in MainActivity as,

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

    }

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


回答1:


CastContext:

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

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



来源:https://stackoverflow.com/questions/51683422/broadcast-receiver-for-cast-connectivity-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!