Currently, the only way to close the notification is by pressing the stop button. But I wonder how can I wrap up the notification widget with a swipeable "thing". Can you tell me any package that would work on this or code that I have to wrap up a thing from the audio_service package?
The audio_service package publisher is - ryanheise.com
As a useful tip, the easiest way to search the entire documentation of audio_service to find an answer to some question is to navigate into the audio_service.dart file (which contains the whole plugin), and then search for the word "swipe". You will find this option on AudioServiceConfig:
/// Whether the Android service should switch to a lower priority state when
/// playback is paused allowing the user to swipe away the notification. Note
/// that while in this lower priority state, the operating system will also be
/// able to kill your service at any time to reclaim resources.
final bool androidStopForegroundOnPause;
And then inside the AudioHandler:
/// Handle the notification being swiped away (Android).
Future<void> onNotificationDeleted();
(You may find this easier to search than reading the online HTML documentation.)
What the above means is that you need to pass androidStopForegroundOnPause: true as a parameter to AudioServiceConfig and then if you want to handle any special behaviour other than the default (stop the service) when the user swipes away the notification, you can optionally override onNotificationDeleted in your own audio handler. There is no equivalent for iOS.
Note that it is not possible to swipe away the Android notification while audio is playing, but the option mentioned above will allow you to swipe away the notification from the paused state.
Related
im making audio player with flutter and i wanna make undraggable notification in which i ll have next, prev, play/pause, add to favorite, change looping mod and dispose the notification actions (last not important). how i can do it?
i use assets_audio_player package but there i can not add all my action and i looked for in flutter_local_notifications package but also found nothing yet
So my project has the different navigation logic based on how user launch my app: by tap the icon laucher or via FCM's notification's tap. The case is I don't know if the FCM's onLaunch callback is gonna be called or not to decide which logic to use. Is there any good approach to this problem?
You can check how your activitiy is started like this (You can use invoke method of flutter to get this result in flutter)
if("android.intent.action.MAIN".equals(getIntent().getAction())){
// By taping the icon launcher
}else{
//By other source
}
I am at a point where I need to detect if any of the hardware buttons was presses when the flutter app is in foreground or when it is open.*
For example, when someone presses a volume or another button (even if it is the power off one) I want to perform some action in my app.
I know that when a flutter app is open and I am looking at the app logs and I tap any hardware button is tapped the lops related to that tap is printed in the logs.
Like when I press Vol down Key Down Tap Detected related logs are printed in logs.
How do can I perform a function when any of the above specified action is performed?
New plugin called Hardware Buttons was released just a few days ago.
It supports volume button events and power button events, which seems like fits your need.
Maybe have a go with this?
You will need find the proper flutter packages to do so.
Any system level call needs to use the platform channel api
https://flutter.io/platform-channels/
Here is the repository
https://pub.dartlang.org/flutter/
Here is an example of a method channel.
https://github.com/flutter/plugins/blob/master/packages/device_info/lib/device_info.dart
Here is an example of a stream listener.
https://github.com/flutter/plugins/tree/master/packages/sensors
The stream listener wasn't really well documented when I tried to grab mic fragments.
I'm having a very simple problem with my implemented 3D Touch dynamic quick action shortcuts.
I want the shortcuts to be cleared whenever the app is terminated (by double clicking the Home button and swiping up).
I am calling UIApplication.sharedApplication().shortcutItems.removeAll() as follows:
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
UIApplication .sharedApplication().shortcutItems?.removeAll()
self.saveContext()
}
However it has no effect, and the quick actions still show when 3D touch is used.
If I place UIApplication.sharedApplication().shortcutItems?.removeAll() inside
func applicationDidEnterBackground(application: UIApplication), this works exactly as intended...
I read something about applicationDidEnterBackground being the function used in most cases due to background processing or something...but there has to be a way to achieve what I want when the user terminates the app using the app monitor swipe up.
Thanks
Didn't tried this. But this tweak should work.
Start a background task on applicationWillTerminate and end it after some small delay. In the mean time, you can call 'UIApplication .sharedApplication().shortcutItems?.removeAll()'.
This will hopefully clear the shortcut items.
There are dynamic and static quick actions. The first kind you define through the shortcutItems property of the UIApplication instance (like in your example). The second kind you register in the plist file.
From the documentation:
Your code creates dynamic quick actions, and registers them with your app object, at runtime.
The system registers your static quick actions when your app is installed.
If a user installs an update for your app but has not yet launched the update, pressing your Home screen icon shows the dynamic quick actions for the previously-installed version.
This means that even when the app is closed the system remembers about both kinds of quick actions. While your app is in memory, such as when going into background, the system can still query the UIApplication for the dynamic actions but it must keep some other sort of persistence of quick actions when the app is closed.
I think there is just no guarantee about the point at which the system synchronizes with the dynamic quick actions. My guess is that the system does not necessarily synchronize when closing the app, yours might be an unsupported use case.
We've got a Chrome app with working notifications, but the notification only lasts a few seconds and then goes away. Our end users are going to want that notification to stay until they dismiss it. Can that be done? We couldn't find anything in the API documentation regarding notification duration.
Update
Since Chrome 50, you can make a notification persist until dismissed with requireInteraction flag:
Indicates that the notification should remain visible on screen until the user activates or dismisses the notification. This defaults to false.
Old answer
You can't make a chrome.notifications notification last forever.
You can sort of control the duration with the priority parameter. From the relevant article (not the main documentation):
Notifications can be assigned a priority between -2 to 2. Priorities < 0 are only shown in the center; priorities > 0 are shown for increasing duration and more high priority notifications can be displayed in the system tray.
Note: if you call update changing the notification's priority, it will be re-shown as needed. You can, in principle, try to exploit that to stay visible.
If you do not need features provided by Rich Notifications, you can use web standard Notification API.
They look similar in Chrome, but do not integrate with the Message Center. As such, they do not disappear unless dismissed by user or programmatically.