I have created an application with Flutter. When we receiving notification from firebase campaign messaging It’s not showing the app icon but when we are receiving from api it’s working fine no problem at all. The problem is identified on motorola phone as of now.
I’m attaching My code here Please help If you know or ever fixed this problem
void main() async {
WidgetsFlutterBinding.ensureInitialized();
CacheHelper.init();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
AwesomeNotifications().initialize(
null, //Icon
[
//! initializing notification
NotificationChannel(
channelKey: '1',
channelName: 'example',
channelDescription: 'notification',
ledColor: Colors.green,
playSound: true,
enableVibration: true,
enableLights: true,
),
NotificationChannel(
channelKey: "0",
channelName: ‘example’,
channelDescription: 'notification',
channelGroupKey: 'notification_group',
ledColor: Colors.green,
playSound: true,
enableVibration: true,
// locked: true,
enableLights: true,
importance: NotificationImportance.Max,
),
],
);
FirebaseMessaging.onMessage.listen((message) async {
notificationProvider.fetchNotification();
if (message.data['action'] == true) {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 99,
channelKey: "0",
title: message.data['title'],
body: message.data['body'],
payload: {
'data': jsonEncode(message.data),
},
),
actionButtons: [
NotificationActionButton(
key: "y", label: "Yes", actionType: ActionType.SilentAction),
NotificationActionButton(
key: "n", label: "No", actionType: ActionType.SilentAction),
]);
} else {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: int.parse(message.data['notification_id']),
channelKey: "0",
roundedBigPicture: true,
title: message.data['title'],
hideLargeIconOnExpand: true,
displayOnBackground: true,
backgroundColor: darkgreen,
customSound: message.data['sound'],
payload: {
'data': jsonEncode(message.data),
},
// locked: true,
body: message.data['body'],
bigPicture: message.data['image'],
notificationLayout: NotificationLayout.BigPicture,
criticalAlert: true,
category: NotificationCategory.Recommendation,
autoDismissible: true));
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// getFCMToken().then((value) {
// log('FCM token : ${value}');
// token = value!;
// loginProvider.setFirebase_token(value);
// });
runApp(
MultiProvider(providers: [
ChangeNotifierProvider<ProfileDataProvider>.value(
value: profileDataProvider),
ChangeNotifierProvider<NotificationProvider>.value(
value: notificationProvider),
ChangeNotifierProvider<LoginProvider>.value(value: loginProvider),
], child: MyApp()),
);
//! for background app notification
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// log(Notification_Data: ${jsonEncode(message.data)}");
if (message.data['action'] == true) {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 99,
channelKey: "0",
title: message.data['title'],
body: message.data['body'],
payload: {
'data': jsonEncode(message.data),
},
),
actionButtons: [
NotificationActionButton(
key: "y", label: "Yes", actionType: ActionType.SilentAction),
NotificationActionButton(
key: "n", label: "No", actionType: ActionType.SilentAction),
]);
} else {
await AwesomeNotifications()
.createNotification(
content: NotificationContent(
groupKey: 'notification_group',
id: int.parse(message.data['notification_id']),
channelKey: '0',
roundedBigPicture: true,
title: message.data['title'],
// locked: true,
hideLargeIconOnExpand: true,
displayOnBackground: true,
backgroundColor: darkgreen,
customSound: message.data['sound'],
autoDismissible: true,
payload: {
'data': jsonEncode(message.data),
},
body: message.data['body'],
bigPicture: message.data['image'],
notificationLayout: NotificationLayout.BigPicture,
criticalAlert: true,
category: NotificationCategory.Message,
actionType: ActionType.Default,
))
.then((value) {
// log(Created Notificaction $value");
}).catchError((e) {
log(e.toString());
});
}
}
[enter image description here](https://i.sstatic.net/7CvzlpeK.jpg)
I want to know the cause of this issue and as It’s not happening all the devices so I don’t know where to start. I’m also sharing my gradle setting
buildscript {
repositories {
// ...
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
// ...
// OneSignal-Gradle-Plugin
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '4.1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
}
compileSdkVersion 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.farm.android"
minSdkVersion 21
targetSdkVersion 34
versionCode 54
// versionCode 7 old
// targetSdkVersion flutter.targetSdkVersion
// versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.facebook.android:facebook-android-sdk:latest.release'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.onesignal:OneSignal:3.12.7'
implementation 'com.android.support:multidex:2.0.1'
}
My manifest setting
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.farmdss.android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:allowBackup="false"
android:label=“Farm"
android:name="androidx.multidex.MultiDexApplication"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="farm.page.link"
android:scheme="https"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="io.flutter.embedding.android.EnableImpeller"
android:value="true" />
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="pushnotificationapp"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<!-- <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" /> -->
</application>
</manifest>
Soumyajit Das is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.