Git Product home page Git Product logo

flutter_ringtone_player's Introduction

flutter_ringtone_player

A simple ringtone, alarm & notification player plugin.

pub package flutter

Usage

Add following import to your code:

import 'package:flutter_ringtone_player/flutter_ringtone_player.dart';

Then simply call this to play system default notification sound:

FlutterRingtonePlayer().playNotification();

There's also this generic method allowing you to specify in detail what kind of ringtone should be played:

FlutterRingtonePlayer().play(
  android: AndroidSounds.notification,
  ios: IosSounds.glass,
  looping: true, // Android only - API >= 28
  volume: 0.1, // Android only - API >= 28
  asAlarm: false, // Android only - all APIs
);

Also you can specify a custom ringtone from assets, or provide direct path to file that works for both Android and iOS:

FlutterRingtonePlayer().play(fromAsset: "assets/ringtone.wav");  
FlutterRingtonePlayer().play(fromFile: "assets/ringtone.wav");  

You can specify a platform specific ringtone and it will override the one from assets:

FlutterRingtonePlayer().play(  
 fromAsset: "assets/ringtone.wav", // will be the sound on Android
 ios: IosSounds.glass 			   // will be the sound on iOS
 );  

.play() optional attributes

Attribute Description
bool looping Enables looping of ringtone. Requires FlutterRingtonePlayer().stop(); to stop ringing.
double volume Sets ringtone volume in range 0 to 1.0.
bool asAlarm Allows to ignore device's silent/vibration mode and play given sound anyway.

To stop looped ringtone please use:

FlutterRingtonePlayer().stop();

Above works only on Android, and please note that by default Alarm & Ringtone sounds are looped.

Default sounds

Method Android iOS
playAlarm RingtoneManager.TYPE_ALARM IosSounds.alarm
playNotification RingtoneManager.TYPE_NOTIFICATION IosSounds.triTone
playRingtone RingtoneManager.TYPE_RINGTONE IosSounds.electronic

Note on iOS sounds

If you want to use any other sound on iOS you can always specify a valid Sound ID and manually construct [IosSound]:

FlutterRingtonePlayer().play(
  android: AndroidSounds.notification,
  ios: const IosSound(1023),
  looping: true,
  volume: 0.1,
);

flutter_ringtone_player's People

Contributors

aarajput avatar andzejsw avatar bitsydarel avatar dependabot[bot] avatar engalalfy avatar georgeamgad avatar spodjasek avatar t1ooo avatar wrbl606 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_ringtone_player's Issues

Android 11 release build not working

Hi Team,
It was working in emulator but not working in real device (Android 11). it throw the following error.

E/flutter (19882): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(Exception, Attempt to invoke virtual method 'void android.media.Ringtone.setLooping(boolean)' on a null object reference, null, null)
E/flutter (19882): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581)
E/flutter (19882): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158)
E/flutter (19882):

RingTone is not playing - Use of stream types is deprecated

My ringtone is not working in the webrtc project. The ringtone example worked, but when added to the webrtc project, it does not ring. My minSDK level is 21. The setStreamType() uses SDK < 21.

Here is a part of the messages from the debug/console screen:
D/Ringtone(31862): Default File Path RINGTONE : /oem/OP/MPCS_US/media/audio/ringtones/00_Metro_Jingle.ogg, NOTIFICATION : /system/media/audio/notifications/Crystal.ogg, ALARM : /system/media/audio/alarms/Life_Is_Good_Alarm.ogg
W/Ringtone(31862): Use of stream types is deprecated for operations other than volume control
W/Ringtone(31862): See the documentation of setStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
I/MediaPlayerNative(31862): constructor
I/MediaPlayerNative(31862): setListener
D/MediaPlayerEX(31862): EventHandlerEx
D/RingtoneManagerEx(31862): getActualDefaultRingtoneUri type is 1 uriString iscontent://media/internal/audio/media/216
I/MediaPlayerNative(31862): attachNewPlayer
V/PlayerBase(31862): updateAppOpsPlayAudio: unmuting player, vol=1.0/1.0
I/MediaPlayerNative(31862): MediaPlayer::setVolume(1.000000, 1.000000)
I/MediaPlayerNative(31862): MediaPlayer::setAuxEffectSendLevel(0.000000)
W/MediaPlayer(31862): Use of stream types is deprecated for operations other than volume control
W/MediaPlayer(31862): See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
V/PlayerBase(31862): updateAppOpsPlayAudio: unmuting player, vol=1.0/1.0
I/MediaPlayerNative(31862): MediaPlayer::setVolume(1.000000, 1.000000)
I/MediaPlayerNative(31862): MediaPlayer::setAuxEffectSendLevel(0.000000)
I/MediaPlayerNative(31862): MediaPlayer::setVolume(1.000000, 1.000000)
I/MediaPlayerNative(31862): MediaPlayer::setLooping
I/MediaPlayerNative(31862): setVideoSurfaceTexture
I/MediaPlayerNative(31862): prepare
I/MediaPlayerNative(31862): message received msg=200, ext1=1, ext2=9120
W/MediaPlayerNative(31862): info/warning (1, 9120)
I/MediaPlayerNative(31862): message received msg=1, ext1=0, ext2=0
I/MediaPlayerNative(31862): MediaPlayer::notify() prepared
I/flutter (31862): CANDIDATE LIST
I/flutter (31862): {"candidate":"candidate:842163049 1 udp 1685987071 69.235.60.201 54734 typ srflx raddr 192.168.1.68 rport 54734 generation 0 ufrag 6rIB network-id 4 network-cost 10","sdpMid":"video","sdpMlineIndex":1}
I/MediaPlayerNative(31862): invoke 68
D/Ringtone(31862): Successfully created local player
D/AudioManager(31862): getStreamVolume() streamType= 2 Request Package= com.outafire.church_events
I/MediaPlayer(31862): create HiFiDBObserver
E/MediaPlayer(31862): Hi-Fi DAC Settings DB Error
I/MediaPlayerNative(31862): start
I/MediaPlayerNative(31862): invoke 68
I/MediaPlayerNative(31862): message received msg=6, ext1=0, ext2=0

Please help me with the possible cause of this issue. Thanks.

FileNotFoundException but notification is played

I get this exception every time I run FlutterRingtonePlayer.playNotification(), jet sound is played anyway. Strange is that every time the notification sounds different.
Device is: Xiaomi Mi 9T Pro

D/MediaPlayer(32207): setDataSource() actualUri=file:///system/media/audio/ui/BirdCicadaNotificationDay1.ogg
W/MediaPlayer(32207): Couldn't open content://0@settings/system/notification_sound_cache
W/MediaPlayer(32207): java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
W/MediaPlayer(32207): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149)
W/MediaPlayer(32207): at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
W/MediaPlayer(32207): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1702)
W/MediaPlayer(32207): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1518)
W/MediaPlayer(32207): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1435)
W/MediaPlayer(32207): at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1154)
W/MediaPlayer(32207): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1103)
W/MediaPlayer(32207): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1019)
W/MediaPlayer(32207): at android.media.Ringtone.setUri(Ringtone.java:332)
W/MediaPlayer(32207): at android.media.RingtoneManager.getRingtone(RingtoneManager.java:728)
W/MediaPlayer(32207): at android.media.RingtoneManager.getRingtone(RingtoneManager.java:703)
W/MediaPlayer(32207): at android.media.RingtoneManager.getRingtone(RingtoneManager.java:666)
W/MediaPlayer(32207): at io.inway.ringtone.player.FlutterRingtonePlayerPlugin.onMethodCall(FlutterRingtonePlayerPlugin.java:74)
W/MediaPlayer(32207): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
W/MediaPlayer(32207): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
W/MediaPlayer(32207): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
W/MediaPlayer(32207): at android.os.MessageQueue.nativePollOnce(Native Method)
W/MediaPlayer(32207): at android.os.MessageQueue.next(MessageQueue.java:336)
W/MediaPlayer(32207): at android.os.Looper.loop(Looper.java:181)
W/MediaPlayer(32207): at android.app.ActivityThread.main(ActivityThread.java:7520)
W/MediaPlayer(32207): at java.lang.reflect.Method.invoke(Native Method)
W/MediaPlayer(32207): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
W/MediaPlayer(32207): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
D/Ringtone(32207): Successfully created local player
D/AudioManager(32207): getStreamVolume isRestricted mode = 0

When can we expect notification sound for Flutter web apps?

Hi,
I was looking for a solution for sound notifications for a web app. I created push notifications for the web, it all works well, it just needs some sound.
It would be nice to have notification sound for web apps as well.

Thank you,
Selma

Support custom ringtone as URI

Currently custom ringtone must be in assets and on Android it is converted to URI. It would be nice if direct URI is also supported.

Example use case:
Android app uses Notification Channel. This allows user to change notification ringtone in system settings.
It is possible to retrieve the URI of the notification sound with flutter_local_notifications plugin. Example URI: content://media/external_primary/audio/media/1399?title=Rock%20Concert&canonical=1
It would be nice if we could play the ringtone as well.

FlutterRingtonePlayer not working in Samsung galaxy s22 ultra

hello,
i have used FlutterRingtonePlayer library to play ringtone when video call receiving screen gets open in device.
but one of our client facing issue in Samsung galaxy s22 ultra. it is not playing ringtone in this device.
i have used like this.

FlutterRingtonePlayer.play(fromAsset: "assets/alert.mp3");

can any one tell me what is problem there?

FlutterRingtonePlayer may crash in OPPO mobile (system version is Android5,6,7,8,9,10)

Fatal Exception: java.lang.IllegalStateException
android.media.MediaPlayer._reset (MediaPlayer.java)
android.media.MediaPlayer.reset (MediaPlayer.java:2686)
android.media.Ringtone.destroyLocalPlayer (Ringtone.java:400)
android.media.Ringtone.-wrap1 (Ringtone.java)
android.media.Ringtone$MyOnErrorListener.onError (Ringtone.java:519)
android.media.MediaPlayer$EventHandler.handleMessage (MediaPlayer.java:4419)
android.os.Handler.dispatchMessage (Handler.java:110)
android.os.Looper.loop (Looper.java:232)
android.app.ActivityThread.main (ActivityThread.java:6806)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1103)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:964)

Please Fix this pressing issue and add flutter 3.3.7 support

Note: /Users/4edoc/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_ringtone_player-3.2.0/android/src/main/java/io/inway/ringtone/player/FlutterRingtonePlayerPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Implicit integer conversion warning

I'm using flutter_ringtone_player in my app, and when build it for iOS, I get the following warning

    /Users/zacharytaylor/development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_ringtone_player-2.0.0/ios/Classes/FlutterRingtonePlayerPlugin.m:17:38: warning: implicit
    conversion loses integer precision: 'NSInteger' (aka 'long') to 'SystemSoundID' (aka 'unsigned int') [-Wshorten-64-to-32]
            AudioServicesPlaySystemSound([soundId integerValue]);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~
    1 warning generated.

Deprecate warning

Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_ringtone_player-2.0.0\android\src\main\java\io\inway\ringtone\player\FlutterRingtonePlayerPlugin.java uses or overrides a deprecated API.
Everything works fine, but there is warning visible. Need to fix this, before it causes some more trouble.

Not able to play sound in ios.

How to play ios sound when app is background.
I know its not implemeted in your plugin but i'm curious to know when you going to implement this feature.
Thanks in advance.

looping:false does't work

Hello,
I use the argement looping:false to play one time.
But It play always in looping does't stop.

Can't stop the alarm with FlutterRingtonePlayer.stop() after killing the app.

I'm currently using flutter_ringtone_player package to implement an Alarm application on mobile. I have AlarmManager to help schedule the time to fire FlutterRingtonePlayer.play() when time comes. If i play and stop the alarm without closing my app then everything works fine, but after closing (killing) my app, the command FlutterRingtonePlayer.stop() on the previous scheduled alarm no longer works when the app is reopened.
How can i resolve this? Thank you.

'fromFile' not working

I have stored an audio file in app's document directory (getting the path with 'getApplicationDocumentsDirectory()').

When I tried to play this audio from this path, i am getting the exception: "Please specify the sound source."
the filePath is like, '/data/user/0/......../app_flutter/alarm_sound.mp3'

try {
await FlutterRingtonePlayer().play(
fromFile: filePath );
} catch (e) {
log(e.toString());
}

When I tried to play from assets using 'fromAsset', its working, but can't play this file which is stored in the app

Settings.System.DEFAULT_NOTIFICATION_URI return null

Some phone Settings.System.DEFAULT_NOTIFICATION_URI will return null , HUAWEI P20 , for example.

Please consider the following example

switch (kind) {
                case 1:
                    ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_ALARM);
                    break;
                case 2:
                    ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_NOTIFICATION);
                    break;
                case 3:
                    ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_RINGTONE);
                    break;
                default:
                    result.notImplemented();
            }

deprecated version of the Android embedding

I use this plugin and get a warning like this, how do I fix it?

The plugin `flutter_ringtone_player` uses a deprecated version of the Android embedding To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.

volume and looping not working in my app

Actually I just set and I found that if I change volume 0.1 to 5 or any it doesn't reflect to sound and also I set looping: true but doesn't any reflect.

  `FlutterRingtonePlayer.play(android: AndroidSounds.notification, ios: IosSounds.triTone, volume: 0.1, looping: true);`

I checked with device and simulator too. both has same issue.

Member not found: 'FlutterRingtonePlayer.play'.

flutter_ringtone_player: ^4.0.0+1
main.dart

Error:

Failed to build iOS app
Error (Xcode): lib/main.dart:82:25: Error: Member not found: 'FlutterRingtonePlayer.play'.

...
FlutterRingtonePlayer.play(
android: AndroidSounds.notification,
ios: IosSounds.sentMessage,
volume: 0.1, // Android only - API >= 28
asAlarm: false,
);
...

IDE: Instance member 'play' can't be accessed using static access

flutter_lints should not be dependency

As the header says: I don't know of a reason why this package should depend on the linter. It should probably get moved to a dev dependency so Users of this library are not forced to use the same linter as described here.

wrong type return on plugin

on flutter_ringtone_player/android/src/main/java/io/inway/ringtone/player/FlutterRingtonePlayerPlugin.java:45

            if (!call.hasArgument("android")) {
                return result.notImplemented();
            }

this funcion "onMethodCall" should return void, but here return result.notImplemented();

when I use this code ,my flutter obj can't run on Android.

I tried to fix it to

            if (!call.hasArgument("android")) {
                result.notImplemented();
                return;
            }

It will work will.

I am poor with github, so I didn't know how to Pull requests. I believe other one can do it better. thanks.

How to stop Flutter Ringtone Player on background notification

i was use the flutter ringtone player on background and the sound is playing, now i want to stop it on the notification where is the notification has action button (using awesomenotification), it is not working and i found some reference on this github issues but it's not working to me

the code on the main :

Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  log("Handling a background body: ${message.notification!.body}");
  await Firebase.initializeApp();
  String? body = message.notification!.body;
  if (body != null) {
    if (body.contains('Public Safety Center')) {
      ReceivePort receiver = ReceivePort();
      IsolateNameServer.registerPortWithName(receiver.sendPort, isolateName);

      receiver.listen((message) async {
        print('uhuy listennn');
        if (message == "stop") {
          await FlutterRingtonePlayer.stop();
        }
      });
      FlutterRingtonePlayer.play(
        fromAsset: 'assets/sound/vintage_alarm.wav',
        volume: 0.8,
        looping: false,
        asAlarm: true,
      );
      await AwesomeNotifications().createNotification(
        content: NotificationContent(
          id: message.notification.hashCode,
          channelKey: 'alerts',
          title: message.notification!.title,
          body: message.notification!.body,
          notificationLayout: NotificationLayout.Default,
          wakeUpScreen: true,
          category: NotificationCategory.Alarm,
          locked: true,
          autoDismissible: false,
          summary: 'Notif',
        ),
        actionButtons: [
          NotificationActionButton(
            key: 'STOP',
            label: 'stop',
            actionType: ActionType.SilentBackgroundAction,
            isDangerousOption: false,
          )
        ],
      );
    }
  }
}

the main :

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  await FirebaseApi().initNotification();
  await NotificationController.initializeIsolateReceivePort();
  await NotificationController.initializeLocalNotifications();
  await NotificationController.startListeningNotificationEvents();
  await dotenv.load(fileName: '.env');
  runApp(const MyApp());
}

and the notification controller :

class NotificationController {
  static ReceivedAction? initialAction;

  ///  *********************************************
  ///     INITIALIZATIONS
  ///  *********************************************
  ///
  static Future<void> initializeLocalNotifications() async {
    await AwesomeNotifications().initialize(
      // 'assets/logo/logo_bsc_warna.png',
      null,
      [
        NotificationChannel(
          channelKey: 'alerts',
          channelName: 'Alerts',
          channelDescription: 'Notification tests as alerts',
          playSound: true,
          onlyAlertOnce: true,
          groupAlertBehavior: GroupAlertBehavior.Children,
          importance: NotificationImportance.High,
          defaultPrivacy: NotificationPrivacy.Private,
          defaultColor: primaryColor,
          ledColor: primaryColor,
        )
      ],
      debug: true,
    );

    // Get initial notification action is optional
    initialAction = await AwesomeNotifications()
        .getInitialNotificationAction(removeFromActionEvents: false);
  }

  static ReceivePort? receivePort;
  static Future<void> initializeIsolateReceivePort() async {
    receivePort = ReceivePort('Notification action port in main isolate')
      ..listen(
          (silentData) => onActionReceivedImplementationMethod(silentData));

    // This initialization only happens on main isolate
    IsolateNameServer.registerPortWithName(
        receivePort!.sendPort, 'notification_action_port');
  }

  ///  *********************************************
  ///     NOTIFICATION EVENTS LISTENER
  ///  *********************************************
  ///  Notifications events are only delivered after call this method
  static Future<void> startListeningNotificationEvents() async {
    log('start listening notification');
    AwesomeNotifications().setListeners(
      onActionReceivedMethod: onActionReceivedMethod,
      onDismissActionReceivedMethod: onDismissActionReceivedMethod,
      onNotificationCreatedMethod: onNotificationCreatedMethod,
      onNotificationDisplayedMethod: onNotificationDisplayedMethod,
    );
  }

  ///  *********************************************
  ///     NOTIFICATION EVENTS
  ///  *********************************************
  ///
  @pragma('vm:entry-point')
  static Future<void> onActionReceivedMethod(
      ReceivedAction receivedAction) async {
    log('action : $receivedAction');
    if (receivedAction.actionType == ActionType.SilentBackgroundAction ||
        receivedAction.actionType == ActionType.SilentAction) {
      log('SILENT ACTION');
      stopAudio();
    }
    stopAudio();
    log('receivee action : ${receivedAction.actionType}');

    return onActionReceivedImplementationMethod(receivedAction);
  }

  @pragma("vm:entry-point")
  static Future<void> onNotificationCreatedMethod(
      ReceivedNotification receivedNotification) async {
    // Your code goes here
    log('MASUK CREATE');
  }

  /// Use this method to detect every time that a new notification is displayed
  @pragma("vm:entry-point")
  static Future<void> onNotificationDisplayedMethod(
      ReceivedNotification receivedNotification) async {
    // Your code goes here
    log('MASUK DISPLAYED');
  }

  /// Use this method to detect if the user dismissed a notification
  @pragma("vm:entry-point")
  static Future<void> onDismissActionReceivedMethod(
      ReceivedAction receivedAction) async {
    // Your code goes here
    log('MASUK DISMISS');
    stopAudio();
  }

  static Future<void> onActionReceivedImplementationMethod(
      ReceivedAction receivedAction) async {
    log('RECEIVE GENG UHUY');
    navKey.currentState!.pushAndRemoveUntil(
        MaterialPageRoute(
          builder: (context) => const BerandaView(),
        ), (action) {
      return true;
    }
        // '/notification-page',
        // (route) => (route.settings.name != '/notification-page') || route.isFirst,
        // arguments: receivedAction,
        );
  }

  ///  *********************************************
  ///     REQUESTING NOTIFICATION PERMISSIONS
  ///  *********************************************
  ///
  static Future<bool> displayNotificationRationale() async {
    bool userAuthorized = false;
    BuildContext context = navKey.currentContext!;
    await showDialog(
        context: context,
        builder: (BuildContext ctx) {
          return AlertDialog(
            title: Text('Get Notified!',
                style: Theme.of(context).textTheme.titleLarge),
            content: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  children: [
                    Expanded(
                      child: Image.asset(
                        logo,
                        height: MediaQuery.of(context).size.height * 0.3,
                        fit: BoxFit.fitWidth,
                      ),
                    ),
                  ],
                ),
                const SizedBox(height: 20),
                const Text(
                    'Allow Awesome Notifications to send you beautiful notifications!'),
              ],
            ),
            actions: [
              TextButton(
                  onPressed: () {
                    Navigator.of(ctx).pop();
                  },
                  child: Text(
                    'Deny',
                    style: Theme.of(context)
                        .textTheme
                        .titleLarge
                        ?.copyWith(color: Colors.red),
                  )),
              TextButton(
                  onPressed: () async {
                    userAuthorized = true;
                    Navigator.of(ctx).pop();
                  },
                  child: Text(
                    'Allow',
                    style: Theme.of(context)
                        .textTheme
                        .titleLarge
                        ?.copyWith(color: Colors.deepPurple),
                  )),
            ],
          );
        });
    return userAuthorized &&
        await AwesomeNotifications().requestPermissionToSendNotifications();
  }

  ///  *********************************************
  ///     NOTIFICATION CREATION METHODS
  ///  *********************************************
  ///
  static Future<void> createNewNotification(RemoteMessage remoteMessage,
      {bool isPsc = false}) async {
    bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
    if (!isAllowed) isAllowed = await displayNotificationRationale();
    if (!isAllowed) return;
    // AwesomeNotifications().
    if (isPsc) {
      log('open the audio');
      await FlutterRingtonePlayer.play(
        fromAsset: 'assets/sound/vintage_alarm.wav',
        volume: 0.05,
        looping: true,
        asAlarm: true,
      );
    }
    log('psc ?? $isPsc');
    RemoteNotification? remoteNotification = remoteMessage.notification;
    Map<String, String?>? payload = {
      'uhuy': 'uhuy',
    };
    await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: remoteNotification.hashCode, // -1 is replaced by a random number
        channelKey: 'alerts',
        title: remoteNotification!.title,
        body: remoteNotification.body,
        // icon: 'assets/logo/logo_bsc_warna.png',
        //'asset://assets/images/balloons-in-sky.jpg',
        notificationLayout: NotificationLayout.Default,
        wakeUpScreen: true,
        // criticalAlert: true,
        locked: isPsc ? true : false,
        autoDismissible: false,
        summary: 'Notif',
        payload: payload,
      ),
      actionButtons: !isPsc
          ? null
          : [
              NotificationActionButton(
                key: 'STOP',
                label: 'stop',
                actionType: ActionType.DismissAction,
                isDangerousOption: false,
              )
            ],
    );
  }

  static Future<void> createNewNotificationSchedule(RemoteMessage remoteMessage,
      {bool isPsc = false}) async {
    bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
    if (!isAllowed) isAllowed = await displayNotificationRationale();
    if (!isAllowed) return;

    RemoteNotification? remoteNotification = remoteMessage.notification;
    Map<String, String?>? payload = {
      'uhuy': 'uhuy',
    };

    await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: remoteNotification.hashCode, // -1 is replaced by a random number
        channelKey: 'alerts',
        title: remoteNotification!.title,
        body: remoteNotification.body,
        notificationLayout: NotificationLayout.Default,
        wakeUpScreen: true,
        locked: isPsc ? true : false,
        autoDismissible: false,
        summary: 'Notif',
        payload: payload,
        customSound: 'assets/sound/vintage_alarm.wav',
        displayOnBackground: true,
        displayOnForeground: true,
      ),
      // schedule: NotificationInterval(
      //   interval: 60,
      //   preciseAlarm: true,
      //   repeats: true,
      //   timeZone: AwesomeNotifications.localTimeZoneIdentifier,
      // ),
      actionButtons: !isPsc
          ? null
          : [
              NotificationActionButton(
                key: 'STOP',
                label: 'stop',
                actionType: ActionType.DismissAction,
                isDangerousOption: false,
              )
            ],
    );
  }

  static Future<void> resetBadgeCounter() async {
    await AwesomeNotifications().resetGlobalBadge();
  }

  static Future<void> cancelNotifications() async {
    await AwesomeNotifications().cancelAll();
  }
}

please tell me if this issue can be solve, thankyou

Android V2 embedding

The plugins flutter_ringtone_player use a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

In release sdk 2.5.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.