Implementing nearby connections in the background service - flutter

I have implemented nearby_connections in my flutter app for sending data between two flutter apps. Everything works fine when the app is in foreground and running.
The problem occurs when i want to implement it in the background and want to have my one flutter app to be discoverable all the time. when the particular adviser is close, it should connect automatically and send some data without any user interaction.
got this exception when implementing the background service with nearby connections.
Exceptions i got.
E/MethodChannel#nearby_connections( 9094): Failed to handle method call
E/MethodChannel#nearby_connections( 9094): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference
E/MethodChannel#nearby_connections( 9094): at androidx.core.app.ActivityCompat$Api23Impl.requestPermissions(ActivityCompat.java:893)
E/MethodChannel#nearby_connections( 9094): at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:557)
E/MethodChannel#nearby_connections( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:147)
E/MethodChannel#nearby_connections( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#nearby_connections( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/MethodChannel#nearby_connections( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/MethodChannel#nearby_connections( 9094): Failed to handle method call
E/MethodChannel#nearby_connections( 9094): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference
E/MethodChannel#nearby_connections( 9094): at androidx.core.app.ActivityCompat$Api23Impl.requestPermissions(ActivityCompat.java:893)
E/MethodChannel#nearby_connections( 9094): at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:557)
E/MethodChannel#nearby_connections( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:125)
E/MethodChannel#nearby_connections( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#nearby_connections( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/MethodChannel#nearby_connections( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/MethodChannel#nearby_connections( 9094): Failed to handle method call
E/MethodChannel#nearby_connections( 9094): java.lang.NullPointerException: Null activity is not permitted.
E/MethodChannel#nearby_connections( 9094): at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement##17.5.0:11)
E/MethodChannel#nearby_connections( 9094): at com.google.android.gms.common.api.GoogleApi.<init>(com.google.android.gms:play-services-base##17.5.0:4)
E/MethodChannel#nearby_connections( 9094): at com.google.android.gms.location.SettingsClient.<init>(com.google.android.gms:play-services-location##17.1.0:3)
E/MethodChannel#nearby_connections( 9094): at com.google.android.gms.location.LocationServices.getSettingsClient(com.google.android.gms:play-services-location##17.1.0:8)
E/MethodChannel#nearby_connections( 9094): at com.pkmnapps.nearby_connections.LocationHelper.requestLocationEnable(LocationHelper.java:97)
E/MethodChannel#nearby_connections( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:112)
E/MethodChannel#nearby_connections( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#nearby_connections( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#nearby_connections( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#nearby_connections( 9094): at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#nearby_connections( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/MethodChannel#nearby_connections( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/MethodChannel#nearby_connections( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter ( 9094): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference
E/flutter ( 9094): at androidx.core.app.ActivityCompat$Api23Impl.requestPermissions(ActivityCompat.java:893)
E/flutter ( 9094): at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:557)
E/flutter ( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:147)
E/flutter ( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter ( 9094): at android.os.Looper.loop(Looper.java:313)
E/flutter ( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/flutter ( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/flutter ( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter ( 9094): )
E/flutter ( 9094): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter ( 9094): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter ( 9094): <asynchronous suspension>
E/flutter ( 9094):
E/flutter ( 9094): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference
E/flutter ( 9094): at androidx.core.app.ActivityCompat$Api23Impl.requestPermissions(ActivityCompat.java:893)
E/flutter ( 9094): at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:557)
E/flutter ( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:125)
E/flutter ( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter ( 9094): at android.os.Looper.loop(Looper.java:313)
E/flutter ( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/flutter ( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/flutter ( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter ( 9094): )
E/flutter ( 9094): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter ( 9094): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter ( 9094): <asynchronous suspension>
E/flutter ( 9094):
E/flutter ( 9094): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Null activity is not permitted., null, java.lang.NullPointerException: Null activity is not permitted.
E/flutter ( 9094): at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement##17.5.0:11)
E/flutter ( 9094): at com.google.android.gms.common.api.GoogleApi.<init>(com.google.android.gms:play-services-base##17.5.0:4)
E/flutter ( 9094): at com.google.android.gms.location.SettingsClient.<init>(com.google.android.gms:play-services-location##17.1.0:3)
E/flutter ( 9094): at com.google.android.gms.location.LocationServices.getSettingsClient(com.google.android.gms:play-services-location##17.1.0:8)
E/flutter ( 9094): at com.pkmnapps.nearby_connections.LocationHelper.requestLocationEnable(LocationHelper.java:97)
E/flutter ( 9094): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin.onMethodCall(NearbyConnectionsPlugin.java:112)
E/flutter ( 9094): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter ( 9094): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 9094): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 9094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 9094): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter ( 9094): at android.os.Looper.loop(Looper.java:313)
E/flutter ( 9094): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/flutter ( 9094): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 9094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/flutter ( 9094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter ( 9094): )
E/flutter ( 9094): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter ( 9094): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter ( 9094): <asynchronous suspension>
E/flutter ( 9094): #2 Nearby.enableLocationServices (package:nearby_connections/src/nearby.dart:193:7)
E/flutter ( 9094): <asynchronous suspension>
E/flutter ( 9094): #3 BluetoothDiscovery.startDiscovery (package:testing_flutter_nearby_connection_with_background_services/bluetooth_service.dart:23:5)
E/flutter ( 9094): <asynchronous suspension>
E/flutter ( 9094):
I have searched a lot and tried all the flutter background or foreground packages. Haven't got any step further after spending a lot of time.
Any one who have faced the same use case and implemented it,or someone who has developed this nearby_connections plugin , kindly share some knowledge.

Related

The Android view returned from PlatformView was already added to a parent view

I encountered this error but I got no luck in finding a solution on this. Any idea on how I can resolve or at least try to understand what is the issue? Thanks!
E/flutter (18634): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: The Android view returned from PlatformView#getView() was already added to a parent view.
E/flutter (18634): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:238)
E/flutter (18634): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/flutter (18634): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/flutter (18634): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (18634): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (18634): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (18634): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter (18634): at android.os.Looper.loop(Looper.java:313)
E/flutter (18634): at android.app.ActivityThread.main(ActivityThread.java:8751)
E/flutter (18634): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (18634): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/flutter (18634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter (18634): , null, null)
E/flutter (18634): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter (18634): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter (18634): <asynchronous suspension>
E/flutter (18634): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1146:18)
E/flutter (18634): <asynchronous suspension>
E/flutter (18634): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:792:5)
E/flutter (18634): <asynchronous suspension>
I tried to check the layout explorer but I haven't see any PlatformView so I'm stuck.

error when using better player in flutter

E/MethodChannel#better_player_channel: Failed to handle method call
java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/flutter: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior., null, java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
#2 MethodChannelVideoPlayer.setDataSource (package:better_player/src/video_player/method_channel_video_player.dart:118:5)
#3 VideoPlayerController._setDataSource (package:better_player/src/video_player/video_player.dart:408:5)
#4 BetterPlayerController._setupDataSource (package:better_player/src/core/better_player_controller.dart:444:9)
#5 BetterPlayerController.setupDataSource (package:better_player/src/core/better_player_controller.dart:274:5)
I face this problem when I use better_player in flutter, It was work good but now show this problem .
Any one can help me

Flutter Firebase Machine Learning Custom model

I have a method thats called to load models but seems to crash every time I call it, I followed the documentation for it I believe so I dont understand why.
Future loadModel() async {
await FirebaseModelDownloader.instance
.getModel(
"Breed-Detector",
FirebaseModelDownloadType.latestModel,
FirebaseModelDownloadConditions(
iosAllowsCellularAccess: true,
iosAllowsBackgroundDownloading: false,
androidChargingRequired: false,
androidWifiRequired: false,
androidDeviceIdleRequired: false,
))
.then((customModel) async {
final localModelPath = customModel.file;
Tflite.close();
String res;
res = (await Tflite.loadModel(
model: localModelPath.toString(), labels: "assets/labels.txt"))!;
print("Models Loading status: ${res}");
});
}
I get the error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0'
but I have the model uploaded
tried uploading a separate model and that seemed to try and download it at first but failed again.
/ModelFileDownloadSer( 7365): Need to download a new model.
D/ModelFileDownloadSer( 7365): Schedule a new downloading task: 64
D/ModelFileDownloadSer( 7365): Model downloaded successfully
D/ModelFileDownloadSer( 7365): Moving downloaded model from external storage to destination folder.
D/ModelFileDownloadSer( 7365): Moved the downloaded model to destination folder successfully: /data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds
E/flutter ( 7365): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0'
E/flutter ( 7365): at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
E/flutter ( 7365): at android.content.res.AssetManager.openFd(AssetManager.java:898)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.loadModel(TflitePlugin.java:210)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:98)
E/flutter ( 7365): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter ( 7365): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 7365): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 7365): at android.os.Looper.loop(Looper.java:223)
E/flutter ( 7365): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 7365): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 7365): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 7365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 7365): , null)

better_player stop working after add video_trimmer in flutter

Better_Player worked before adding Video_Trimmer, but after I added Video_Trimmer, it stopped playing the video, and if I remove Video_Trimmer again, Better_Player works.
Things I tested:
Uninstalling and reinstalling the application
Using lower versions of Better_Player
better_player: ^0.0.83
video_trimmer: ^1.1.3
console error is:
E/MethodChannel#better_player_channel(18557): Failed to handle method call
E/MethodChannel#better_player_channel(18557): java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
E/MethodChannel#better_player_channel(18557): at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
E/MethodChannel#better_player_channel(18557): at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
E/MethodChannel#better_player_channel(18557): at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
E/MethodChannel#better_player_channel(18557): at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
E/MethodChannel#better_player_channel(18557): at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
E/MethodChannel#better_player_channel(18557): at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
E/MethodChannel#better_player_channel(18557): at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
E/MethodChannel#better_player_channel(18557): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#better_player_channel(18557): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#better_player_channel(18557): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#better_player_channel(18557): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#better_player_channel(18557): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#better_player_channel(18557): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#better_player_channel(18557): at android.os.Looper.loopOnce(Looper.java:210)
E/MethodChannel#better_player_channel(18557): at android.os.Looper.loop(Looper.java:299)
E/MethodChannel#better_player_channel(18557): at android.app.ActivityThread.main(ActivityThread.java:8273)
E/MethodChannel#better_player_channel(18557): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#better_player_channel(18557): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
E/MethodChannel#better_player_channel(18557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1073)
E/flutter (18557): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior., null, java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
E/flutter (18557): at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
E/flutter (18557): at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
E/flutter (18557): at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
E/flutter (18557): at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
E/flutter (18557): at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
E/flutter (18557): at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
E/flutter (18557): at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
E/flutter (18557): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (18557): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (18557): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (18557): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (18557): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (18557): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (18557): at android.os.Looper.loopOnce(Looper.java:210)
E/flutter (18557): at android.os.Looper.loop(Looper.java:299)
E/flutter (18557): at android.app.ActivityThread.main(ActivityThread.java:8273)
E/flutter (18557): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (18557): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
E/flutter (18557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1073)
E/flutter (18557): )
E/flutter (18557): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (18557): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (18557): <asynchronous suspension>
E/flutter (18557): #2 MethodChannelVideoPlayer.setDataSource (package:better_player/src/video_player/method_channel_video_player.dart:118:5)
E/flutter (18557): <asynchronous suspension>
E/flutter (18557): #3 VideoPlayerController._setDataSource (package:better_player/src/video_player/video_player.dart:408:5)
E/flutter (18557): <asynchronous suspension>
E/flutter (18557): #4 BetterPlayerController._setupDataSource (package:better_player/src/core/better_player_controller.dart:485:9)
E/flutter (18557): <asynchronous suspension>
E/flutter (18557): #5 BetterPlayerController.setupDataSource (package:better_player/src/core/better_player_controller.dart:274:5)
E/flutter (18557): <asynchronous suspension>
E/flutter (18557):
W/System (18557): A resource failed to call close.
I/BufferQueueProducer(18557): [SurfaceView[com.example.meetbin/com.example.meetbin.MainActivity]#5(BLAST Consumer)5](id:487d00000006,api:1,p:18557,c:18557) disconnect: api 1
I/BufferQueueProducer(18557): [SurfaceView[com.example.meetbin/com.example.meetbin.MainActivity]#5(BLAST Consumer)5](id:487d00000006,api:0,p:-1,c:18557) disconnect: api -1
I/BufferQueueProducer(18557): [ViewRootImpl[MainActivity]#4(BLAST Consumer)4](id:487d00000005,api:1,p:18557,c:18557) disconnect: api 1
I/BLASTBufferQueue(18557): [ViewRootImpl[MainActivity]#4] destructor()
I/BufferQueueConsumer(18557): [ViewRootImpl[MainActivity]#4(BLAST Consumer)4](id:487d00000005,api:0,p:-1,c:18557) disconnect
D/DecorView[](18557): onWindowFocusChanged hasWindowFocus false
i was facing the same issue now fixed by following this #1085
to fix this just use this better_player version :
replace
better_player: ^0.0.83
by
better_player:
git:
url: https://github.com/tintran-dev/betterplayer.git
also make sure you have added the formatType for m3u8 and mdp
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"url",
videoFormat: BetterPlayerVideoFormat.hls,
drmConfiguration: BetterPlayerDrmConfiguration(
drmType: BetterPlayerDrmType.token,
token: "Bearer=token",
),
);

Flutter local notifications throwing an error

While trying to show the notifications from flutter_local_notification it throws the following error:
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:188)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:146)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:688)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:827)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:750)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/flutter (10962): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter (10962): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (10962): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (10962): <asynchronous suspension>
E/flutter (10962): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter (10962): #3 AndroidFlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:137:21)
E/flutter (10962): #4 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:136:13)
E/flutter (10962): #5 NotificationPlugin.showNotification (package:pig_salang/models/notification_plugin.dart:94:43)
E/flutter (10962): #6 WelcomeScreen.build.<anonymous closure> (package:pig_salang/screens/welcome_screen.dart:42:36)
E/flutter (10962): #7 WelcomeScreen.build.<anonymous closure> (package:pig_salang/screens/welcome_screen.dart:41:26)
E/flutter (10962): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
E/flutter (10962): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
E/flutter (10962): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (10962): #11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter (10962): #12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter (10962): #13 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
E/flutter (10962): #14 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter (10962): #15 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter (10962): #16 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (10962): #17 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter (10962): #18 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (10962): #19 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (10962): #20 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (10962): #21 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (10962): #22 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (10962): #23 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (10962): #24 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (10962): #25 _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter (10962): #26 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (10962): #27 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (10962): #28 _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter (10962): #29 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter (10962):
As far as I have researched, the similar errors were shown because of the icon. I have added used every possible way to add icons, but it is not throwing the error constantly. Obviously, I rerun the app after each changes, to make sure I don't get the error.
My code looks like:
initializePlatformSpecifics() {
var initializeAndroidSettings = AndroidInitializationSettings('app_icon'); <--- Here
var initializeIOSSettings = IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: true,
requestSoundPermission: true,
onDidReceiveLocalNotification: (id, title, body, payload) async {
ReceivedNotification receivedNotification = ReceivedNotification(
id: id, title: title, body: body, payload: payload);
didReceivedLocalNotificationSubject.add(receivedNotification);
},
);
initializeSettings = InitializationSettings(
initializeAndroidSettings, initializeIOSSettings);
}
I followed the tutorial. The thing is when I try to show the notification, it shows the above traceback.
I made notification icons in Android Studio -> app -> main -> res -> Image Asssets -> Notifications icon, then I made icon with name app_icon which I used to intialize the notification.
As it was not working, I also tried :
var initializeAndroidSettings = AndroidInitializationSettings('#mipmap/ic_launcher');
It also did not work. Any help would be appreciated!!!
'app_icon' was given for reference and it actually depends on where you image file is located, if you are using the default icon in mipmap folder named as ic_launcher for now then try the below code. Do let me know if it helps.
var initializeAndroidSettings
=AndroidInitializationSettings('mipmap/ic_launcher');