How to set a Flutter Custom Notification Icon ?,because there is no default notification icon in flutter for fcm - flutter

I want to set a custom notification icon to appear in my notifications panel for my flutter app when i use fcm(firebase cloud messaging) but there is only a grey circle that appears and no icon .

After Searching for a long time i finally found the answer and here it is:
Create a custom notification icon using this tool.
Paste the generated list of icons in android/app/src/main/res.
Go to your manifest android/app/src/main/AndroidManifest.xml and add the following meta data in the application (not activity) tag:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorPrimary" />
If you don't have a colors.xml in res/values, create one:
Done! It should work, let me know if it doesn't.
Discussion for the question is here.

Related

Unable to use local storage in flutter web view

I am using flutter_inappwebview: ^5.3.0 package in my app, i am achieving every requirement of my app except I can't upload picture in my web view.
As soon as i click the icon the app crashes.
I have tried achieving this with flutter_webview_plugin but there are number of other issues i can't solve with that, so i decided to give inappwebview a try, but i am stil stuck at this.
On Android, you need to add the following codes inside the tag of your android/app/src/main/AndroidManifest.xml:
<provider
android:name="com.pichillilorenzo.flutter_inappwebview.InAppWebViewFileProvider"
android:authorities="${applicationId}.flutter_inappwebview.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>

Incorrect Icon in notification center

I have an app which receives the push notifications and display them even if screen is locked.
Icon shown in notification bar is not correct. My project is developed in flutter and app icon is working fine. Where exactly I need to keep the icon file to show correct icon on notification panel. Please refer image below.
Have you tried adding below code in your AndroidManifest.xml,
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
For more read this
I did the following and it worked for me:
Create a transparent and white notification icon (you can use the following tool: AndroidAssetStudio )
Download the zip folder, unzip and you'll see it contains a res folder with different drawable folders. Copy and paste the contents of the res folder in "android\app\src\main\res" path
Then open the AndroidManifest.xml file and add the following lines to it:
ic_stat_calendar_today is the name of my notification icon. And each of the drawable folders that have been pasted contain a different size of icon with the same name.
If you want to change the color of the icon then check the above image. Add the metadata tag after the notification icon tag
Go to "android\app\src\main\res\values" and add a colors.xml file
<color name="colorAccent">#00FF00</color>
I have shared this answer in the following Github chain as well- Solution.

How to remove the bottom navigation bar in a TWA?

I have build a TWA as described at https://developers.google.com/web/updates/2019/02/using-twa
I want to remove the bottom navigation bar. I have read that it can only be done programmatically with IMMERSIVE mode : https://developer.android.com/training/system-ui/immersive.html
So i need to add a Class associated to the activity "android.support.customtabs.trusted.LauncherActivity" and to add the hideSystemUI() code in onCreate() i guess.
How to do that ?
Here is the manifest :
....
<activity
android:name="android.support.customtabs.trusted.LauncherActivity"
android:theme="#style/Theme.LauncherActivity"
android:label="#string/app_name">
....
How to code the immersive mode for this activity ?
Using Bubblewrap
When using Bubblewrap (recommended), you will be asked which display mode the application should use as part of the init command.
If you have already initialized the application, modify twa-manifest.json, set display to fullscreen.
In AndroidManifest.xml
When building the application yourself and using the default LauncherActivity, you can get set the following meta-tag as part of the Activity definition in AndroidManifest.xml:
<meta-data android:name="android.support.customtabs.trusted.DISPLAY_MODE"
android:value="immersive" />

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

Android: two tasks - two launcher icons

I have an activity A (i want that work in background) that start activity B with code
moveTaskToBack(false);
Intent intent = new Intent(context.getActivity(), BActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(intent);
In manifest i have
<activity android:name="ru.nekit.BActivity"
android:label="B"
android:taskAffinity="ru.nekit"/>
When start activity B and press Home button i see that there is two launcher icons
Question how can i do that wiil be only one launche icon?
Your app may have multiple activities found in your launcher based upon your manifest file and the XML attribute:
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
For each activity that you list containing this attribute, you will have another icon found within the Launcher for that activity. Make sure you only have this attribute set for the activity you want to display in the launcher.
You may also have installed multiple versions of your app when developing if you ended up changing the application name somewhere along the way. Be sure to uninstall all previous versions.