Make a Chromecast Mini Controller sticky - android

We have created a video app for Android and we have also connected it with the Chromecast library. We created a Mini Controller in the notification bar and lock screen using this exact code here.
Problem: the Mini Controller can be dismissed as a regular notification instead staying sticky, like the Mini Controller in the YouTube app.
I have found how to make a sticky regular notification, but not how to alter the one given in the Chromecast Docs.

You are probably using deprecated SDK version (v2?) in which the notification is not sticky. If you do casting using the new Cast SDK (Cast Application Framework (CAF)), the notification will be sticky automatically.

Related

Two notifications from MediaSessionCompat

My app can play music from the internet. For control, I use a push notification with buttons for pause/play and rewind. I create it via NotificationCompat Builder and set the MediaStyle. On the lock screen, MediaSessionCompat displays a full-screen notification for monitoring. But there is also a duplicate of the first notification. Because of this, I have two notifications on the lock screen.
Perhaps the MediaSession itself should hide the notification by its id or channel? I tried setting VISIBILITY_SECRET to the channel and notification, but it also displayed on the lock screen.
This may be behavior specific to your phone; I would first start by checking what the behavior is on an emulator.
Perhaps you'd like to compare how you're registering your MediaSession in the notification against the Universal Android Music Player Sample. In particular, check if you've set the MediaSession token with the MediaStyle notification using setMediaSession(); you can find how this is accomplished inside UAMP inside UampNotificationManager.

Show notification only on phone (not on Android Wear)

Is there any way to prevent a notification be shown on Android Wear device? I know it's possible by using setOngoing(true) but I don't want my notification to be ongoing.
you should call setLocalOnly(true) on the NotificationCompat.Builder.
From the documentation
Set whether or not this notification should not bridge to other
devices.
you can read more here

Creating Wearable notifications without the builder?

Is it possible to create wearable notifications without using the notification builder?
I already create a notification via new Notification on newer devices and would like to keep that code and still add the Wearable notification to my existing one. Is this possible, or is everything connected to the builder helper class for now?
It seems that there is no WearableNotifications.Builder class anymore in the newest SDK.
But you need to do nothing to simply let your Notification show on Android Wear Devices.
If you want to have a slightly better look for your Notifications you can use WearableExtender to add Android Wear specific actions, pages and layout options.
The WearableNotifications.Builder class is only needed if you want to add 'wearable extensions' to your notification. The normal notifications shown by your app are displayed also on the wearable connected to your device without any further integration work.

How to Implement inbox style and bigtext style notifications in android 2.2 version?

As Notification.Compact is part of android support library, they should be supported on android 4.0 and below, but I'm not able to see inbox style notification in android 4.0 as well. It works perfectly on android 4.2.
Handling compatibility
Not all notification features are available for a particular version, even though the methods to set them are in the support library class NotificationCompat.Builder. For example, action buttons, which depend on expanded notifications, only appear on Android 4.1 and higher, because expanded notifications themselves are only available on Android 4.1 and higher.
To ensure the best compatibility, create notifications with NotificationCompat and its subclasses, particularly NotificationCompat.Builder. In addition, follow this process when you implement a notification:
Provide all of the notification's functionality to all users, regardless of the version they're using. To do this, verify that all of the functionality is available from an Activity in your app. You may want to add a new Activity to do this.
For example, if you want to use addAction() to provide a control that stops and starts media playback, first implement this control in an Activity in your app.
Ensure that all users can get to the functionality in the Activity, by having it start when users click the notification. To do this, create a PendingIntent for the Activity. Call setContentIntent() to add the PendingIntent to the notification.
Now add the expanded notification features you want to use to the notification. Remember that any functionality you add also has to be available in the Activity that starts when users click the notification.
refer to this Link

How to make notification like phone app

In samsung galaxy tab 2 when phone app goes to background, we can interact with phone app from notification. it has all the buttons and information that we need.
How can i implement notification like this?
First of all you can add functional buttons to your Notification just on devices running Honeycomb or later. Yes, some pre Honeycomb devices have those kind of Notifications, but only the device manufacturers were able to build such Notifications (examples for Dialer or Music Player).
To use such a notification you could use a customView for your Notification (have a look at RemoteViews).
An easier way,(and the recommended way) would be to use NotificationCompat.Builder and use the addAction method, wich will add a button to your Notification and execute the PendingIntent that you specify, when that button is clicked. This will also work on pre Honeycomb devices, meaning that on older devices will not show the button.
EDIT: you can refer to this great tutorial from Vogella : Android Notifications.

Categories

Resources