Google cast v3 notification and foreground service notification - android

I am using ExoPlayer in foreground service together with MediaStyle notification and MediaSessionToken to control playback. I also want to be able to Cast the content to Google Cast receiver. This could be the normal use case for every music player.
The cast is creating its own notification so I have 2 notifications to control the same playback which is bad UX.
I have found this SO question link to disable the default cast notification by setting .setNotificationOptions(null). The problem is that the system creates another notification "A device on your Wi-Fi is casting" as seen on the screenshot. This is the notification that is shown on every device in the same network.
My question is: Is it possible to share the same notification for foreground service and cast service?
Or at least tell the system that this is the device that is actually sending the cast, so it won't show the silent system notification "A device on your Wi-Fi is casting" on that particular device?
Thank you.

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.

Does Beacon Notification Can wake up terminated app

I have project need to add notifications with Beacons。I have some questions wanna to make sure.
does os can receive beacon notification without APP running?
Can we show different showing content depend on different beacon notification?
can we open terminated app by beacon notification?
can the app do different behavior depend by the beacon notification content after start up?
Thanks。
1- How beacon works
The Android Beacon Library can launch your app into the background to
start looking for beacons after the phone boots. This will happen
transparently with no visible user interface, while the rest of your
app remains idle.
Once the desired beacon is detected, a callback method fires where you
can push a custom notification message. You can further configure the
notification so it launches a specific part of your app when pressed.
2- different notification
Yes ! each beacon has its id and you can handle showing different notification depending on the id and also different content
3- lunching app
Yes ! you can add your logic in the services that handle beacon notification method to start the preferred activity.
WARNING: launching a UI without any user interaction is a very very bad practice for most of the applications!
[...] Interrupting what the user is currently doing is considered bad
design form, especially from something that is supposed to be
operating in the background. Therefore, you should consider using a
Notification [...] to launch the desired Activity when the user
decides it is time to investigate. [...]
4- App behavior
Yes ! all you have to do is setting your pendingIntent accordingly to the notification

Silent notifications in foreground services

I have multiple apps that kind of work together to do the same job and they all belong to the same developer. Each app runs a long-running service in the background and keeps processing user's input. The problem is that those services cannot run in the background for a long time because Android system will kill them. So I want to use foreground services instead of background ones to prevent the system from killing them. However, I don't want to annoy the users with multiple different notifications in the notification drawer.
I found out that creating a notification without assigning a channel in Android O, will let the system start the foreground service without showing a notification. Something like the following:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle(......);
builder.setTicker(......);
builder.setContentText(......);
builder.setSmallIcon(......);
builder.setLargeIcon(......);
Notification notification = builder.build();
startForeground(111, notification);
So I was thinking of showing a notification by creating a notification with a channel from one app and create a notification without a channel for the other apps as I described earlier. In that case, the user will see one notification for all my apps.
That solution works well for me. But I am wondering if it is an unintended use of the notification in the foreground services. I am afraid that Google will suspend my apps for doing that!!
Do you guys know if it is okay to implement that solution?
Or is there any way to stack the notifications together in a group even though they are different apps?
My goal is just to make the notification less annoying to the user.
Also, I am aware of JobScheduler & JobIntentService solutions. But they don't do the job in my case because I want to keep the service running. Not like do one job and stop the service...
You can create notification channel with IMPORTANCE_LOW (https://developer.android.com/training/notify-user/channels#importance).
There shouldn't be sound.
Or you can also use setOnlyAlertOnce() (https://developer.android.com/training/notify-user/build-notification#Updating) and the sound will be only once.

Create an (repetitive high pitch) Alarm on a remote trigger when App is not running (iphone/android) just like Find My iPhone

I would like to cause an alarm on a remote iphone/android device when the app is running or not running.
How do I achieve it ?
I can only think of Whatsapp/Skype when there is incoming call, its ringing.
Or would it be possible to cause the phone to play a looping alarm sound on Push Notification.
Another very clear example is "Find My iPhone" app which can trigger a loud alarm to an iPhone.
How can I achieve this programmatically on ios and android ?
Its possible using FireBase Notification Services with JobService & FirebaseMessagingService.
Download the FireBase samples from here .Run module "messaging".I tested it and I was able to receive the notification , even in the Application killed state.
To manage events periodically/scheduled you must implement & deploy your Server somewhere.You can also check FireBase Functions (Beta) to easily implement Server.
To show something (Alaram/UI like calling screen) to user start your custom Activity while receiving FireBase notification.Override handleIntent from FirebaseMessagingService.So that you can receive data from your killed/idle Application.
FireBase Service is System Service & it will be always running.Please have a read.
Code snippet
#Override
public void handleIntent(Intent intent) {
super.handleIntent(intent);
// Get Data here
Log.d(TAG, "intent.."+intent.getExtras());
Intent intent1=new Intent(this,MainActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
Note : Some devices (Eg; ASUS's Mobile Manager) may reject to start Application's receiver while , Notification arrives.In that case please provide appropriate permissions.
1 possible solution could be schedule alarm event with repeatInterval on receiving push notification.
EDIT
We can create custom notifications using Notification extensions.They are called as soon as notification arrives & we can present customized view with image/video downloading. So you can try there to schedule events.
For iOS, you will need a server to deliver a push notification to your app, where the notification references a custom audio alert to be played. The audio alert has to be included within the app's bundle as stated in Apple docs.
This alert can't be longer than 30 seconds. If you want the alert to be played longer, you can send send another push notification times roughly 30-seconds after and stop sending the alert when a) user open the app or b) you've reached the maximum threshold.
It's generally not good practise to send multiple notification containing the same payload, unless there is a good reason.
I would suggest splitting up this question into two: one for iOS, and another for Android.

Foreground service android wear

I didn't find any documentation about that. Is it possible to create a foreground service on android wear? Usually the foreground state is related with an ongoing notification but it's not possible on wear so I'm a bit confused. Is there anyone has a foreground service on wear?
As per documentation:
"The system enforces a timeout period. If you are displaying an activity and user's don't interact with it, the device sleeps. When it wakes back up, the Wear home screen is displayed instead of your activity. If you need to show something persistent, create a notification in the context stream instead."
So, i believe it's possible to have a persistent UI (may be not an ongoing foreground notification but a card or a stack instead).
Hope it helps.

Categories

Resources