{"id":22479094,"url":"https://github.com/ftadev/fcm-example","last_synced_at":"2025-07-30T23:10:29.639Z","repository":{"id":204679586,"uuid":"712408094","full_name":"FtADev/FCM-Example","owner":"FtADev","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-05T09:27:46.000Z","size":631,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T21:28:19.122Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FtADev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-31T12:16:10.000Z","updated_at":"2023-10-31T12:17:20.000Z","dependencies_parsed_at":"2023-11-05T10:26:17.247Z","dependency_job_id":null,"html_url":"https://github.com/FtADev/FCM-Example","commit_stats":null,"previous_names":["ftadev/fcm-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FtADev%2FFCM-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FtADev%2FFCM-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FtADev%2FFCM-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FtADev%2FFCM-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FtADev","download_url":"https://codeload.github.com/FtADev/FCM-Example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245898944,"owners_count":20690592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T15:13:02.864Z","updated_at":"2025-03-27T18:23:04.570Z","avatar_url":"https://github.com/FtADev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firebase Cloud Messaging Example\n\n## Getting Started\n\nCreate a [firebase](https://console.firebase.google.com/project/) project.\n\nadd name and continue\n\nthen click on Android\n\n![img.png](img.png)\n\nGo to \u003cyour-project\u003e/android/app/src/main/AndroidManifest.xml\n\ncopy \"package\" name (if does not have, add it at the end of xmlns: `package=\"com.example.fcm_example\"`)\n\nadd it in firebase console\n\n![img_1.png](img_1.png)\n\nand click on Register app.\n\ndownload `google-services.json` and put it under /src folder and add next.\n\nTo make the google-services.json config values accessible to Firebase SDKs, you need the Google services Gradle plugin.\n\nAdd the plugin as a dependency to your project-level build.gradle.kts file:\n\nRoot-level (project-level) Gradle file (\u003cproject\u003e/build.gradle):\n\n```\ndependencies {\n        ...\n        classpath 'com.google.gms:google-services:4.4.0'\n    }\n```\n\nThen, in module (app-level) Gradle file (\u003cproject\u003e/\u003capp-module\u003e/build.gradle):\n\n```\nplugins {\n  \n  // Add the Google services Gradle plugin\n  id \"com.google.gms.google-services\"\n}\n\ndependencies {\n  // Import the Firebase BoM\n    implementation platform('com.google.firebase:firebase-bom:32.4.1')\n\n  // TODO: Add the dependencies for Firebase products you want to use\n  // When using the BoM, don't specify versions in Firebase dependencies\n  //implementation(\"com.google.firebase:firebase-analytics-ktx\")\n\n\n  // Add the dependencies for any other desired Firebase products\n  // https://firebase.google.com/docs/android/setup#available-libraries\n}\n```\n\nAfter adding the plugin and the desired SDKs, sync your Android project with Gradle files.\n\n## Send Background Notification\n\nAfter adding `firebase_api` and changing `main` method in [first commit](https://github.com/FtADev/FCM-Example/commit/a7e8b03663afd963c8756678d9266b1414126f83) and [second commit](https://github.com/FtADev/FCM-Example/commit/4979ec2c8b77e8bf328e074421b6bb11d1dbf157)\n\nyou can push a notification from your firebase console \n\nGo to your project page\n\n![img_2.png](img_2.png)\n\n![img_3.png](img_3.png)\n\n![img_4.png](img_4.png)\n\nAfter filling the fields click on send test message\n\n![img_5.png](img_5.png)\n\nHere you can add your token (That we were printing on the code) to target that specific device and click on add icon.\n\nput the app in the background (or terminate it) and click on test!\n\n## Routing\n\nIf you want to route to a specific screen by clicking on notification, you can see these commits:\n\n1. [Add screens](https://github.com/FtADev/FCM-Example/commit/15f934c6974b19840c3202416d31eb6faa991ae8)\n\n2. [Handle Messages](https://github.com/FtADev/FCM-Example/commit/8914a8cdc8275cca64b35324bed14537b2045957)\n\n## Local Notifications\n\nWhat should we do if we want to receive a notification when app is in foreground?\n\nJust follow [this commit](https://github.com/FtADev/FCM-Example/commit/23bc2f58b405085def4785dc0e44e25c9bef9015)!\n\nThanks to [HeyFlutter](https://www.youtube.com/watch?v=k0zGEbiDJcQ)\n\n## Postman\n\nIf you want to send notification from postman:\n\nGo to your project in firebase console:\n\nProject Overview-\u003eProject Settings-\u003eCloud messaging-\u003e Enable `Cloud Messaging API (Legacy)`\n\n![img_6.png](img_6.png)\n\nthen copy the `Server Key`\n\nIn Postman: \n\nCreate a new request:\n\nURL:\n\n```\n    https://fcm.googleapis.com/fcm/send\n```\n\nMethod:\n\n```\n    POST\n```\n\nHeader:\n\n``` \n   \"Content-Type\": \"application/json\",\n   \"Authorization\": \"key=\u003cServer_key\u003e\"\n```\n\nBody:\n\n```\n    {\n     \"to\": \"\u003cyour-device-token\u003e\",\n     \"notification\": {\n       \"title\": \"Push Notification\",\n       \"body\": \"Test Push Notification\",\n       \"something\": \"somewhere\"\n     },\n     \"data\": {\n       \"title\": \"data title\",\n       \"message\": \"data message\",\n       \"something\": \"anotherthing\"\n     }\n   }\n```\n\n(`data` part is payload)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fftadev%2Ffcm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fftadev%2Ffcm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fftadev%2Ffcm-example/lists"}