Flutter: FCM not sending notifications on android release
Fcm notifications used to work like a charm but in my last 2 releases, they do not work in any way. I do not have my app released to the App Store yet so I am not sure if the problem is about the whole project or just about android. I am not really sure where the problem is.
this is my flutter doctor output:
[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-TR)
• Flutter version 1.22.4 at /Users/adnanfahed/flutter
• Framework revision 1aafb3a8b9 (12 days ago), 2020-11-13 09:59:28 -0800
• Engine revision 2c956a31c0
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/adnanfahed/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.10.0
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin installed
• Dart plugin version 201.9245
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.51.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.16.0
[✓] Connected device (1 available)
• iPhone (mobile) • 7c0edb93134cbbf0493eb34ada73e295cffa68cf • ios • iOS 14.2
1 answer
-
answered 2020-11-25 06:54
biruk IS
you have to register release sha-1 key to firebase console. on terminal write
cd android
thengradlew signingreport
this command will show you your keys. register the key that says release sha-1 and it will work.
See also questions close to this topic
-
Flutter: Crash in release mode for android V2 upgrade
I upgrade my android to V2 and now my app crash at the splash screen in release mode.
This is the error I see
Caused by java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:292) at io.flutter.view.FlutterMain.ensureInitializationComplete(FlutterMain.java:8) at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:10) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3542) at android.app.ActivityThread.-wrap4(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6938) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I am using Flutter 1.22.4
Please let me know how to fix this issue.
Thanks
-
How to remove vertical space between GridView rows
I'm new to kotlin and I am developing an app that uses a gridview. I've managed to make the gridview work, however I want to remove the space between each row. I've tried setting padding and vertical spacing to 0dp, my listSelector is @null but nothing seems to work. What should I do to remove the vertical space between rows?
Grid View:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <GridView android:id="@+id/home_grid" android:numColumns="3" android:verticalSpacing="0dp" android:horizontalSpacing="0dp" android:background="@color/colorPrimary" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="top" android:stretchMode="columnWidth" android:listSelector="@null" android:gravity="center" android:paddingVertical="0dp"/> </RelativeLayout>
Image View:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <ImageView android:id="@+id/grid_image" android:layout_width="200dp" android:layout_height="200dp" android:adjustViewBounds="true"/> </RelativeLayout>
-
Cordova Sending Data From Android Java to Javascript
I am working with Cordova and the inAppBrowser plugin for Android. I am trying to expand upon a previous question,
https://stackoverflow.com/questions/65534821/cordova-inappbrowser-hide-show-in-java-android/65627954?noredirect=1#comment116337002_65627954
where the inAppBrowser hardware back button was linked to the Javascript .hide function, to hide the browser but not exit it. This problem was solved, however created a new problem, inAppBrowser does not have a visibility status to say if it is either shown or hidden to the user.
I would like to send a message from Java to Cordova Javascript with the hide update.
Here is were we left off
I edited InAppBrowserDialog.java
I added
import org.apache.cordova.CordovaArgs; import org.json.JSONArray;
And added inside the
public class InAppBrowserDialog extends Dialog {
the following
public void hideDialog() { CordovaArgs args = new CordovaArgs(new JSONArray()); try { this.inAppBrowser.execute("hide", args, new FakeCallbackContext()); } catch (JSONException e) { e.printStackTrace(); } } public void showDialog() { CordovaArgs args = new CordovaArgs(new JSONArray()); try { this.inAppBrowser.execute("show", args, new FakeCallbackContext()); } catch (JSONException e) { e.printStackTrace(); } }
I then created a new java file in the same directory, called
FakeCallbackContext.java
And placed the following code inside
package org.apache.cordova.inappbrowser; import org.apache.cordova.CallbackContext; import org.apache.cordova.PluginResult; class FakeCallbackContext extends CallbackContext { public FakeCallbackContext() { super(null, null); } @Override public void sendPluginResult(PluginResult pluginResult) { // Do not send an actual result to the webview // Perhaps just log the result //<<<< This is where I need to send an update back to a Cordova listener //<<<< so I can let Cordova know that the inAppBrowser is now hidden } }
I have tried to incorporate several different solutions, such as
webView.loadUrlNow("javascript:" + js);
But from what I have read you have to be inside the main Cordova class, and not a plugin.
-
How can I save the page route with Shared Preferences on Flutter?
I want to save the page route in the Shared preferences so I can be navigated to the same page after restarting the app.
-
How to import xml file to dart object
I'm trying to import an xml file exported by c# XmlSerializer to dart object using xml package but all my tries of importing failed.
<?xml version="1.0" encoding="utf-8"?> <ArrayOfViewReads xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ViewReads> <CounterAccount>7e7386db-ae4e-47f8-a473-8a5534b8b421</CounterAccount> <ParentCounter>00000000-0000-0000-0000-000000000000</ParentCounter> <CounterGuid>88165f87-113b-4503-bd95-01cfc778cf0e</CounterGuid> <CounterID>354</CounterID> <AccountName>يحي العامر</AccountName> <AreaName>مربع الشارع العام وغزه</AreaName> <AddressDesc>منطقه الوء الاخضر</AddressDesc> <Phone>771707009</Phone> <FazName>سنجل فاز</FazName> <Balance>865.0000</Balance> <LastRead>7332.00</LastRead> </ViewReads> <ViewReads> <CounterAccount>46e2bacc-644f-47fb-abe7-6589f880667e</CounterAccount> <ParentCounter>00000000-0000-0000-0000-000000000000</ParentCounter> <CounterGuid>2d2f1a40-9dcf-4a3c-9fd2-081d3be83aaa</CounterGuid> <CounterID>2052</CounterID> <AccountName>كمال محمد علي ثامر</AccountName> <AreaName>مربع الشارع العام وغزه</AreaName> <AddressDesc>خلف كوافير السلطانه</AddressDesc> <Phone>771363922</Phone> <FazName>سنجل فاز</FazName> <Balance>1560.0000</Balance> <LastRead>84.00</LastRead> <UserGuid>00000000-0000-0000-0000-000000000000</UserGuid> </ViewReads> </ArrayOfViewReads>
And here is my importing code from dart using fromJson() method that generated by VSCode:
final file = File('C:\\Users\\SALMAN\\Desktop\\2021_1_19_559.xml'); final document = XmlDocument.parse(file.readAsStringSync()); document.children.forEach((e) { var v = ViewRead.fromJson(e.toString()); });
And this is the error after I tried running the code:
Unhandled exception: FormatException: Unexpected character (at character 1) <?xml version="1.0" encoding="utf-8"?> ^ #0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5) #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9) #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22) #3 _parseJson (dart:convert-patch/convert_patch.dart:40:10) #4 JsonDecoder.convert (dart:convert/json.dart:505:36) #5 JsonCodec.decode (dart:convert/json.dart:156:41) #6 new ViewRead.fromJson (file:///C:/Users/SALMAN/.IntelliJIdea2019.1/dart/bin/dart.dart:170:70) #7 main.<anonymous closure> (file:///C:/Users/SALMAN/.IntelliJIdea2019.1/dart/bin/dart.dart:16:22) #8 List.forEach (dart:core-patch/growable_array.dart:313:8) #9 _DelegatingIterableBase.forEach (package:collection/src/wrappers.dart:52:45) #10 main (file:///C:/Users/SALMAN/.IntelliJIdea2019.1/dart/bin/dart.dart:15:21) #11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32) #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
-
Running Gradle task 'assembleDebug'. (This is taking an unexpectedly long time.)
when I created a very basic flutter app and ran it for the first time, it works perfectly, and when I try to add some dependencies in my pubspec.yaml file I get no errors in my project but when I run the app by 'flutter run' I get stuck in
Running Gradle task 'assembleDebug'... (This is taking an unexpectedly long time.)
and the app has never worked
this is my pubspec.yaml filename: myPDFApp description: A new Flutter project. publish_to: 'none' version: 1.0.0+1 environment: sdk: ">=2.7.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.0 syncfusion_flutter_pdfviewer: ^18.4.35-beta // this is the dep that I want to add dev_dependencies: flutter_test: sdk: flutter flutter: uses-material-design: true
-
How to display the time elapsed from a timestamp?
To be more precise, I would like to display the number of minutes passed since a timestamp fetched from an API. Should
Stopwatch
orTimer
be used, or something else? -
Firebase Cloud Messaging - Failed to send notification via server
I have an application that sends messages from the Server to Android through Firebase and it works. However, I am developing a new project with "andoirdx" and after the new changes in Firebase I am no longer able to use the same PHP server application as the basis for sending notifications. Using the Firebase console I can send notifications to my application. Here is the code of the PHP server I am using as a base.
send.php
<?php // Enabling error reporting error_reporting(-1); ini_set('display_errors', 'On'); require_once __DIR__ . '/firebase.php'; require_once __DIR__ . '/push.php'; $firebase = new Firebase(); $push = new Push(); $message = isset($_GET['message']) ? $_GET['message'] : ''; $tipo = isset($_GET['tipo']) ? $_GET['tipo'] : ''; $latitude = isset($_GET['latitude']) ? $_GET['latitude'] : ''; $longitude = isset($_GET['longitude']) ? $_GET['longitude'] : ''; $push_type = isset($_GET['push_type']) ? $_GET['push_type'] : ''; $push->setMessage($message); $push->setTipo($tipo); $push->setLatitude($latitude); $push->setLongitude($longitude); $push->setIsBackground(false); $json = ''; $response = ''; if ($push_type == 'global') { $json = $push->getPush(); $response = $firebase->sendToTopic('global', $json); } else if ($push_type == 'individual') { $json = $push->getPush(); $regId = isset($_GET['token']) ? $_GET['token'] : ''; $response = $firebase->send($regId, $json); } echo "Request: ".json_encode($json)."<p>"; echo " - Response: ". json_encode($response)."<p>"; ?>
push.php
<?php class Push { private $message; private $tipo; private $latitude; private $longitude; /* flag indicating whether to show the push notification or not this flag will be useful * when perform some opertation in background when push is recevied */ private $is_background; function __construct() { } public function setMessage($message) { $this->message = $message; } public function setIsBackground($is_background) { $this->is_background = $is_background; } public function setTipo($tipo) { $this->tipo = $tipo; } /** * @param field_type $latitude */ public function setLatitude($latitude) { $this->latitude = $latitude; } /** * @param field_type $longitude */ public function setLongitude($longitude) { $this->longitude = $longitude; } public function getPush() { $res = array(); $res['data']['message'] = $this->message; $res['data']['tipo'] = $this->tipo; $res['data']['latitude'] = $this->latitude; $res['data']['longitude'] = $this->longitude; return $res; } }
firebase.php
<?php class Firebase { // sending push message to single user by firebase reg id public function send($to, $message) { $fields = array( 'to' => $to, 'data' => $message, ); return $this->sendPushNotification($fields); } // Sending message to a topic by topic name public function sendToTopic($to, $message) { $fields = array( 'to' =>'/topics/'. $to, 'data' => $message, ); return $this->sendPushNotification($fields); } // sending push message to multiple users by firebase registration ids public function sendMultiple($registration_ids, $message) { $fields = array( 'to' => $registration_ids, 'data' => $message, ); return $this->sendPushNotification($fields); } // function makes curl request to firebase servers private function sendPushNotification($fields) { require_once __DIR__ . '/config.php'; // Set POST variables $url = 'https://fcm.googleapis.com/fcm/send'; $headers = array( 'Authorization: key=' . FIREBASE_API_KEY, 'Content-Type: application/json' ); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); return $result; } } ?>
config.php
<?php // Firebase API Key define('FIREBASE_API_KEY', 'XXXXXY-xxxx:XXXXXXXxxxxxxxxxxxXXXXXXXXXXXXXXXXXXxxXXXX_XXXXXXXXXXXXXX-0000000-XxX0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); ?>
-
How to sent a notification to all users using FCM?
I am able to sent a custom notification to my own device using Advanced REST Client using this code:
https://fcm.googleapis.com/fcm/send
content-type application/json
Authorization KEY=XXXXXXXXXX
{ "data": { "title": "Update", "content": "Test" }, "to": "cju4nq0nQ9C8YAkVZZ_lh7:APA91bG........ }
I have no idea how to send this to all users. I read something about using topics, but don't know how to apply that here.
Can you point me in a direction or have a solution for this problem?
-
FCM getting registration token from not default FCM service
After update to newest Firebase there is not method for getting FCM registration token for selected fcmSenderId:
FirebaseInstanceId .getInstance() .getToken(fcmSenderId, "FCM")
Documentation says to use FirebaseMessaging instead (https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessaging#getToken()):
FirebaseMessaging .getInstance() .token .addOnCompleteListener { task -> if (task.isSuccessful) { task.result?.let { token -> println(token) } } else { println(task.exception) } }
but this method doesn't allow to provide custom FCM Sender Id.
The project has configured google-services.json but need to use another FCM project.