Custom Flutter Android FirebaseMessagingService - flutter

I'm trying to make a custom FirebaseMessagingService in Android for Flutter to execute Kotlin code on receiving a notification in the background. Does anyone have an example of how this can be done while still receiving the notification/message.data in the main flutter app?
Thanks!

I ended up creating a custom flutter plugin that is run in the background using the FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);

Related

ImageCache is reset to zero when I open iOS plugin by MethodChannel

I am trying to use iOS image picker plugin in my Flutter using MethodChannel.
But I found that if I open and close the image picker(My Image Picker button), ImageCache is reset to zero.
So NetworkImage gets loading again like it has never been downloaded before.
On the other hand, Flutter's image picker(Flutter Image Picker button) doesn't reset ImageCache to zero so it is fine.
Why is this happening? Did I miss something?
I have tried overriding ImageCache size like below but the problem is not solved:
overriding image cache in Flutter
Please help me...
my app home tab
my app image tab
flutter image picker
I recommend to use flutter package to make developer easier to code and even the package also use MethodChannel, inside code is also coded pretty well such as error handler etc. It is also works for IOS and Android, which is this is the function of Flutter that make developer easier to deploy IOS and Android apps.
You can explore more about this:
https://pub.dev/packages/image_picker
https://pub.dev/packages/cached_network_image/example

Is there a way to launch notes application in flutter from button click?

I have a button in my app. On click of the button, I want the notes app in the device to get launched whether iOS or Android. I there a way around this with flutter? I haven't discovered any solution yet.
Yes there is this plugin external_app_launcher will helps you to open another app from your app by providing PackageName for Android and URLscheme for IOS external_app_launcher

Tap Jacking protection for Flutter apps

I have seen that there wont be any way of providing Tap jacking for flutter apps but I came across this
saying,
It is possible to globally disable all touches when obscured by setting this property on the root view in your MainActivity (Kotlin code Sample):
val view = findViewById<View>(android.R.id.content).rootView
view.filterTouchesWhenObscured = true
Any suggestions how to convert the above code in dart Language for Flutter App
There's no solution for this yet by the flutter community.
It's still an open issue on flutter's gh https://github.com/flutter/flutter/issues/40422

Is runApp() method necessary to create a flutter app?

dart code
I expected this code to paint a black colored rectangle to screen but it didn't .I'm using flutter framework and I want to know that don't flutter support making apps like these or any mistake in my code. I just
wanted to make run flutter code without built-in flutter framework library
}
Yes, it's necessary. In dart only execute code inside the main method. Not like JavaScript or Python. It's like java/c. The only execution is the main method.

Flutter show app icon badge on push notification

I'm looking for a way to show an app icon badge when a user receives a push notification.
I'm using the Firebase_messaging plugin for flutter for the handling of the push notifications and flutter_app_badger for the app icon badges.
But I want to combine the two so that the number is set on the icon without opening the app. Is it possible to make this happen? Or am I overlooking something obvious from the firebase_messaging plugin?
Sorry for the horrible explanation. I hope someone can help me with this issue.
App icon badge depends on the Application Launcher
Some of the Android Application Launcher includes this functionality by default, You can check this on Settings->Apps->Notification
Attached image
FYI
How to show notification count on app icon like Facebook?
How does Facebook add badge numbers on app icon in Android?
adding notification badge on app icon in android
My suspicion is that you have an icon that isn't compatible with the icon guidelines in your device. I suggest trying https://pub.dev/packages/flutter_launcher_icons to make icons for your device.
I think you try to create stream when run app to real time listen doc changes in Firestore. Read here How to listen for document changes in Cloud Firestore using Flutter?
And the icon can be update in background but without opening app is impossible I think.
I don't have a direct answer because I haven't encountered this issue before, but this might fix your problem
Ensure that you have defined the icon for your application properly - for flutter, here are the steps you should have:
Import the package into your pubsec.yaml file - it should be called flutter_launcher_icons: "^0.8.0" and imported under the dev-dependencies section of the pubspec.yaml file.
After the dev-dependencies section, add a new section for flutter icons as so:
flutter_icons:
ios: true
android: true
image_path_ios: "{Icon File Path}"
image_path_android: "{Icon File Path}"
Hopefully this helps, and good luck with fixing your issue!
Using https://pub.dev/packages/firebase_messaging for notifications ,
for Android Background notifications you can add this in your AndroidManifest.xml file in your application tag. And make sure you have androidlogo.png (this is example name) present in your drawable folder.
<application>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/androidlogo" />
</application>
In case of foreground notifications, you must be using Flutter Local Notifications, so you can provide the same while initializing like
var initializationSettingsAndroid = new AndroidInitializationSettings('androidlogo');
flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onNotificationClicked);
And for application icon you can use this library https://pub.dev/packages/flutter_launcher_icons which is also suggested by answers above.
In case of iOS, your launcher icon will your notification icon.
And for display of badge icon you can use https://pub.dev/packages/flutter_app_badger. (For supported phones).
So using all this you will get both app icon with badge and notification icon as your app icon (or specified by you).
You can control the badge count from the notification payload.
If you send a notification manually from Firebase Console, you can set the badge count on Additional options step:
If you send it programmatically, add this payload (iOS example):
{"aps":{"alert":"Enter your message","badge":1,"sound":"default"}}
For more payload options, check out FCM documentation