Scott
Scott

Reputation: 2657

CastCompanionLibrary - notification for data app?

I have a data application (a drawing app), and I would like to use the supposed built-in functionality of the CastCompanionLibrary to put up a notification whenever the application is not visible, but it is still casting.

I have the following in my "onResume":

mDataCastManager = DataCastManager.initialize(context, APPLICATION_ID, NAMESPACE);
            mDataCastManager.enableFeatures(DataCastManager.FEATURE_NOTIFICATION |
                    DataCastManager.FEATURE_LOCKSCREEN   |
                    DataCastManager.FEATURE_DEBUGGING);
// ...snip...

mDataCastManager.incrementUiCounter();

and the following in my "onPause":

mDataCastManager.decrementUiCounter();

however, not notification shows up. What do I need to do differently? I can't find anything in the docs, and I can't make sense of the source. I don't see anywhere in the source where notifications are handled at all, actually. What am I missing?

Thanks!

Upvotes: 1

Views: 198

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19084

DataCastManager doesn't have any built-in notifications since the nature of data-centric application can vary greatly so what should be shown there in the notifications is by no means clear. In those cases that I needed to define one, I followed the following steps:

  • Look at the VidoCastNotificationService and copy that and create your own version of it, say MyDataNotificationService. There, you can define how your notification should look like, what PendigIntents you need to call, etc. Most of the code should be the same.
  • Extend DataCastManager. That class is again very generic for the very same reason, so you need to subclass it and add your own logic whenever it needs. In there, write a method called, say, startNotificationService by looking at what the similar method does in VideoCastManager.
  • You most likely want to start the notification service when your application is connected, so follow the pattern in VideoCastManager where that is called and do similar things in your subclass.

There are some other things that you need to do in your subclass that can be very useful but that is a very high-level outline. I have done this for a slideshow app but is not 100% complete yet and recently have been very busy with some other more pressing activities; hopefully at some point (not too far in future) I can get a chance to complete and open source that so folks can have one way of doing what I had outlined above; meanwhile try your own version and ask questions if you run into issues.

Upvotes: 2

Related Questions