1

I have an Android app and I'm trying to integrate google cast into it to try it out by following the instructions at https://developers.google.com/cast/cast_2nd-screen_app_tutorial . The app is built with Android API 16 in mind. Because of this, my app wasn't built with the support libraries. However, a condition to using MediaRouteButton is to extend from FragmentActivity.

Converting the code to use the support libraries instead of the non-support equivalents is turning into a big hassle. Is there an alternative component to use for apps supporting only API 11 and higher? Or do I just forego using MediaRouteButton?

(I see I can write my own button to select the device, but I wouldn't be adding any new functionality to this other than to be compatible with my non-FragmentActivity.)

I'm hoping the activity being a FragmentActivity is only a requirement to use the button, and none of the other MediaRouter APIs.

EDIT: Here is the exception that is thrown.

10-24 17:25:02.568: E/AndroidRuntime(25502): FATAL EXCEPTION: main
10-24 17:25:02.568: E/AndroidRuntime(25502): java.lang.IllegalStateException: The activity must be a subclass of FragmentActivity
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.support.v7.app.MediaRouteButton.showDialog(MediaRouteButton.java:225)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.support.v7.app.MediaRouteButton.performClick(MediaRouteButton.java:285)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.view.View$PerformClick.run(View.java:18350)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.os.Handler.handleCallback(Handler.java:730)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.os.Looper.loop(Looper.java:137)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at android.app.ActivityThread.main(ActivityThread.java:5368)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at java.lang.reflect.Method.invoke(Method.java:525)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1041)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
10-24 17:25:02.568: E/AndroidRuntime(25502):    at dalvik.system.NativeStart.main(Native Method)

EDIT 2: Ah, it appears there is a non-support MediaRouteButton version. It detects the chromecast device under its list of available but it doesn't seem to connect. (This version does not have a setRouteSelector method like the support.v7 version does) but I will try working with this and see if it is an alternative.

EDIT 3: I wrote down what I ended up doing in the Answered section.

echoecho
  • 21
  • 4
  • Please include more information on (a) what version of Android you are developing your app against, (2) the crash log. Once we see those, we will hopefully be able to provide some feedback. – Ali Naddaf Oct 24 '13 at 16:37
  • @AliNaddaf I've updated the question to include the crash log, but I know the reason why it's crashing. I've checked the MediaRouteButton doc and it does say I must use FragmentActivity in order to use the button. So my question is more about alternatives to using MediaRouteButton, and if FragmentActivity is a requirement to use Google Cast in general. I am developing against Android API 16. Thank you for your help. – echoecho Oct 25 '13 at 00:35

1 Answers1

1

Similar to this setup, I modified the MediaRouteButton source to use the APIs meant for supporting Android API level 11+. In this case, it really meant having the class use android.app.FragmentManager instead of android.support.v4.app.FragmentManager. This way I didn't have to remake my existing Activities to extend off of FragmentActivity.

Community
  • 1
  • 1
echoecho
  • 21
  • 4