├── .gitignore ├── CHANGELOG.md ├── FcmSharp ├── Examples │ ├── Android │ │ └── messaging-app │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── app │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── androidTest │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── google │ │ │ │ │ └── firebase │ │ │ │ │ └── quickstart │ │ │ │ │ └── fcm │ │ │ │ │ └── MainActivityEspressoTest.java │ │ │ │ ├── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── google │ │ │ │ │ │ └── firebase │ │ │ │ │ │ └── quickstart │ │ │ │ │ │ └── fcm │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ ├── MyFirebaseMessagingService.java │ │ │ │ │ │ └── MyJobService.java │ │ │ │ └── res │ │ │ │ │ ├── drawable-hdpi-v11 │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-hdpi │ │ │ │ │ ├── firebase_lockup_400.png │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-mdpi-v11 │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-mdpi │ │ │ │ │ ├── firebase_lockup_400.png │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xhdpi-v11 │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ ├── firebase_lockup_400.png │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xxhdpi-v11 │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ ├── firebase_lockup_400.png │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xxxhdpi-v11 │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── drawable-xxxhdpi │ │ │ │ │ └── ic_stat_ic_notification.png │ │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ │ └── values │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ └── screen.png │ │ │ ├── build.gradle │ │ │ ├── gradle.properties │ │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ ├── CSharp │ │ ├── FcmSharp.Example │ │ │ ├── FcmSharp.Example.csproj │ │ │ └── Program.cs │ │ ├── FcmSharp.Examples.sln │ │ ├── FcmSharp.Scheduler.Quartz │ │ │ ├── Database │ │ │ │ ├── ApplicationDbContext.cs │ │ │ │ ├── Configuration │ │ │ │ │ ├── Mapping.cs │ │ │ │ │ └── Seeding.cs │ │ │ │ └── Model │ │ │ │ │ ├── Message.cs │ │ │ │ │ └── StatusEnum.cs │ │ │ ├── Extensions │ │ │ │ └── LoggerExtensions.cs │ │ │ ├── FcmSharp.Scheduler.Quartz.csproj │ │ │ ├── Program.cs │ │ │ ├── Properties │ │ │ │ └── launchSettings.json │ │ │ ├── Quartz │ │ │ │ ├── JobFactory │ │ │ │ │ └── JobFactory.cs │ │ │ │ └── Jobs │ │ │ │ │ └── ProcessMessageJob.cs │ │ │ ├── Services │ │ │ │ ├── Converters │ │ │ │ │ └── MessageConverter.cs │ │ │ │ ├── MessagingService.cs │ │ │ │ └── SchedulerService.cs │ │ │ ├── Startup.cs │ │ │ ├── Testing │ │ │ │ └── MockFcmClient.cs │ │ │ ├── Web │ │ │ │ ├── Contracts │ │ │ │ │ ├── Message.cs │ │ │ │ │ └── StatusEnum.cs │ │ │ │ ├── Controllers │ │ │ │ │ └── SchedulerController.cs │ │ │ │ ├── Converters │ │ │ │ │ └── MessageConverter.cs │ │ │ │ └── Extensions │ │ │ │ │ ├── DatabaseExtensions.cs │ │ │ │ │ └── QuartzExtensions.cs │ │ │ └── appsettings.json │ │ └── FcmSharp.Scheduler │ │ │ ├── Converters │ │ │ └── MessageConverter.cs │ │ │ ├── Database │ │ │ ├── ApplicationDbContext.cs │ │ │ ├── Configuration │ │ │ │ ├── Mapping.cs │ │ │ │ └── Seeding.cs │ │ │ └── Model │ │ │ │ ├── Message.cs │ │ │ │ └── StatusEnum.cs │ │ │ ├── FcmSharp.Scheduler.csproj │ │ │ ├── Program.cs │ │ │ ├── Services │ │ │ └── SchedulerService.cs │ │ │ └── Testing │ │ │ └── MockFcmClient.cs │ └── Images │ │ ├── Screenshot_20181118-100555.png │ │ ├── Screenshot_20181118-100611.png │ │ ├── Screenshot_20181118-101026.png │ │ └── Screenshot_20181118-103856.png ├── FcmSharp.Console │ ├── FcmSharp.ConsoleApp.csproj │ └── Program.cs ├── FcmSharp.Test │ ├── FcmSharp.Test.csproj │ ├── Integration │ │ ├── BatchMessageIntegrationTest.cs │ │ ├── IntegrationTest.cs │ │ └── ProxyIntegrationTest.cs │ └── Requests │ │ ├── AndroidConfigTest.cs │ │ └── ApnsConfigTest.cs ├── FcmSharp.sln ├── FcmSharp │ ├── BackOff │ │ └── ExponentialBackOffSettings.cs │ ├── Batch │ │ └── BatchMessageBuilder.cs │ ├── Exceptions │ │ ├── FcmHttpException.cs │ │ ├── FcmMessageException.cs │ │ └── FcmTopicManagementException.cs │ ├── Extensions │ │ └── FcmClientExtensions.cs │ ├── FcmClient.cs │ ├── FcmSharp.csproj │ ├── FcmSharp.snk │ ├── Http │ │ ├── Builder │ │ │ ├── HttpRequestMessageBuilder.cs │ │ │ ├── HttpRequestUtils.cs │ │ │ └── UrlSegment.cs │ │ ├── Client │ │ │ ├── FcmHttpClient.cs │ │ │ └── IFcmHttpClient.cs │ │ ├── Constants │ │ │ ├── HttpHeaderNames.cs │ │ │ └── MediaTypeNames.cs │ │ └── Proxy │ │ │ ├── ProxyHttpClientFactory.cs │ │ │ └── WebProxy.cs │ ├── IFcmClient.cs │ ├── Requests │ │ ├── AndroidConfig.cs │ │ ├── AndroidMessagePriorityEnum.cs │ │ ├── AndroidNotification.cs │ │ ├── ApnsConfig.cs │ │ ├── ApnsConfigPayload.cs │ │ ├── Aps.cs │ │ ├── ApsAlert.cs │ │ ├── Converters │ │ │ ├── AndroidMessagePriorityEnumConverter.cs │ │ │ ├── BoolToIntConverter.cs │ │ │ └── DurationFormatConverter.cs │ │ ├── FcmMessage.cs │ │ ├── Message.cs │ │ ├── Notification.cs │ │ ├── TopicManagementRequest.cs │ │ ├── WebpushConfig.cs │ │ ├── WebpushFcmOptions.cs │ │ └── WebpushNotification.cs │ ├── Responses │ │ ├── Converters │ │ │ └── TopicErrorEnumConverter.cs │ │ ├── FcmBatchResponse.cs │ │ ├── FcmMessageErrorResponse.cs │ │ ├── FcmMessageResponse.cs │ │ ├── InstanceIdServiceErrorResponse.cs │ │ ├── InstanceIdServiceResponse.cs │ │ ├── TopicMessageResponse.cs │ │ └── TopicMessageResponseError.cs │ ├── Serializer │ │ ├── IJsonSerializer.cs │ │ └── JsonSerializer.cs │ └── Settings │ │ ├── FcmClientSettings.cs │ │ ├── FileBasedFcmClientSettings.cs │ │ ├── IFcmClientSettings.cs │ │ └── StreamBasedFcmClientSettings.cs ├── Images │ ├── OV_Logo.png │ └── jetbrains.png └── NuGet │ ├── FcmSharp.1.0.0.nupkg │ ├── FcmSharp.1.1.0.nupkg │ ├── FcmSharp.2.0.0.nupkg │ ├── FcmSharp.2.1.0.nupkg │ ├── FcmSharp.2.1.1.nupkg │ ├── FcmSharp.2.2.0.nupkg │ ├── FcmSharp.2.3.0.nupkg │ ├── FcmSharp.2.3.1.nupkg │ ├── FcmSharp.2.3.2.nupkg │ ├── FcmSharp.2.4.0.nupkg │ ├── FcmSharp.2.5.0.nupkg │ ├── FcmSharp.2.6.0-alpha.nupkg │ ├── FcmSharp.2.6.0.nupkg │ ├── FcmSharp.2.7.0.nupkg │ ├── FcmSharp.2.7.1.nupkg │ ├── FcmSharp.2.8.0.nupkg │ ├── FcmSharp.2.8.1.nupkg │ ├── FcmSharp.2.8.2.nupkg │ ├── FcmSharp.2.8.3.nupkg │ ├── FcmSharp.2.8.4.nupkg │ ├── FcmSharp.3.0.0.nupkg │ └── FcmSharp.3.0.1.nupkg ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | .idea/ 3 | *.xproj.user 4 | *.csproj.user 5 | project.lock.json 6 | bin/ 7 | obj/ 8 | packages/ 9 | *.DotSettings.user 10 | *.db -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea/ 3 | *.iml 4 | build/ 5 | /local.properties 6 | .DS_Store 7 | /captures 8 | google-services.json 9 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/README.md: -------------------------------------------------------------------------------- 1 | Firebase Cloud Messaging Quickstart 2 | ============================== 3 | 4 | The Firebase Cloud Messaging Android Quickstart app demonstrates registering 5 | an Android app for notifications and handling the receipt of a message. 6 | **InstanceID** allows easy registration while **FirebaseMessagingService** and **FirebaseInstanceIDService** 7 | enable token refreshes and message handling on the client. 8 | 9 | Introduction 10 | ------------ 11 | 12 | - [Read more about Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) 13 | 14 | Getting Started 15 | --------------- 16 | 17 | - [Add Firebase to your Android Project](https://firebase.google.com/docs/android/setup). 18 | - Run the sample on Android device or emulator. 19 | 20 | Sending Notifications 21 | --------------------- 22 | 23 | Use Firebase console to send FCM messages to device or emulator. 24 | 25 | ## Send to a single device 26 | 27 | - From Firebase console Notification section, click **New Message**. 28 | - Enter the text of your message in the Message Text field. 29 | - Set the target to **Single Device**. 30 | - Check the logs for the **InstanceID** token, copy and paste it into the Firebase console Token field. 31 | - If you cannot find the token in your logs, click on the **LOG TOKEN** button in the application and the token will 32 | be logged in **logcat**. 33 | - Click on the **Send Message** button. 34 | - If your application is in the foreground you should see the incoming 35 | message printed in the logs. If it is in the background, a system notification should be 36 | displayed. When the notification is tapped, the application should return to the quickstart application. 37 | 38 | ## Send to a topic 39 | 40 | - From Firebase console Notification section, click **New Message**. 41 | - Enter the text of your message in the Message Text field. 42 | - Click on the **SUBSCRIBE TO NEWS** button to subscribe to the news topic. 43 | - Set the target to **Topic**. 44 | - Select the news topic from the list of topics ("news" in this sample). 45 | You must subscribe from the device or emulator before the topic will will be visible in the console. 46 | - Click on the **Send Message** button. 47 | - If your application is in the foreground you should see the incoming 48 | message printed in the logs. If it is in the background, a system notification should be 49 | displayed. When the notification is tapped, the application should return to the quickstart application. 50 | 51 | Best Practices 52 | -------------- 53 | 54 | ## Android notification channels 55 | 56 | ### Set default channel 57 | 58 | If incoming FCM messages do not specify an Android notification channel, you can indicate 59 | to FCM what channel should be used as the default by adding a metadata element to your 60 | application manifest. In the metadata element specify the ID of the channel that should 61 | be used by default by FCM. 62 | 63 | 66 | 67 | Note: You are still required to create a notification channel in code with an ID that 68 | matches the one defined in the manifest. See the Android [docs](https://goo.gl/x9fh5X) for more. 69 | 70 | ## Customize default notification 71 | 72 | ### Custom default icon 73 | 74 | Setting a custom default icon allows you to specify what icon is used for notification 75 | messages if no icon is set in the notification payload. Also use the custom default 76 | icon to set the icon used by notification messages sent from the Firebase console. 77 | If no custom default icon is set and no icon is set in the notification payload, 78 | the application icon (rendered in white) is used. 79 | 80 | ### Custom default Color 81 | 82 | You can also define what color is used with your notification. Different android 83 | versions use this settings in different ways: Android < N use this as background color 84 | for the icon. Android >= N use this to color the icon and the app name. 85 | 86 | See the [docs](https://goo.gl/sPggnS) for more. 87 | 88 | Result 89 | ----------- 90 | 91 | 92 | Support 93 | ------- 94 | 95 | - [Stack Overflow](https://stackoverflow.com/questions/tagged/firebase-cloud-messaging) 96 | - [Firebase Support](https://firebase.google.com/support/) 97 | 98 | License 99 | ------- 100 | 101 | Copyright 2016 Google, Inc. 102 | 103 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 104 | license agreements. See the NOTICE file distributed with this work for 105 | additional information regarding copyright ownership. The ASF licenses this 106 | file to you under the Apache License, Version 2.0 (the "License"); you may not 107 | use this file except in compliance with the License. You may obtain a copy of 108 | the License at 109 | 110 | http://www.apache.org/licenses/LICENSE-2.0 111 | 112 | Unless required by applicable law or agreed to in writing, software 113 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 114 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 115 | License for the specific language governing permissions and limitations under 116 | the License. 117 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | check.dependsOn 'assembleDebugAndroidTest' 3 | 4 | android { 5 | compileSdkVersion 27 6 | 7 | defaultConfig { 8 | applicationId "com.google.firebase.quickstart.fcm" 9 | minSdkVersion 16 10 | targetSdkVersion 27 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled true 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | packagingOptions { 25 | exclude 'LICENSE.txt' 26 | } 27 | 28 | lintOptions { 29 | abortOnError false 30 | } 31 | } 32 | 33 | configurations.all { 34 | resolutionStrategy.force 'com.android.support:support-annotations:27.1.1' 35 | } 36 | 37 | repositories { 38 | google() 39 | } 40 | 41 | dependencies { 42 | implementation 'com.android.support:appcompat-v7:27.1.1' 43 | implementation 'com.android.support:animated-vector-drawable:27.1.1' 44 | implementation 'com.android.support:support-v4:27.1.1' 45 | implementation 'com.android.support:support-compat:27.1.1' 46 | 47 | implementation 'com.google.firebase:firebase-core:16.0.3' 48 | implementation 'com.google.firebase:firebase-iid:17.0.1' 49 | implementation 'com.google.firebase:firebase-messaging:17.3.1' 50 | implementation 'com.firebase:firebase-jobdispatcher:0.8.5' 51 | 52 | // Testing dependencies 53 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 54 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 55 | androidTestImplementation 'com.android.support.test:rules:1.0.2' 56 | androidTestImplementation 'com.android.support:support-annotations:27.1.1' 57 | } 58 | 59 | apply plugin: 'com.google.gms.google-services' 60 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keepattributes EnclosingMethod 20 | -keepattributes InnerClasses 21 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/androidTest/java/com/google/firebase/quickstart/fcm/MainActivityEspressoTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.firebase.quickstart.fcm; 18 | 19 | import android.support.test.rule.ActivityTestRule; 20 | import android.support.test.runner.AndroidJUnit4; 21 | import android.test.suitebuilder.annotation.LargeTest; 22 | import android.view.View; 23 | 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | 28 | import static android.support.test.espresso.Espresso.onView; 29 | import static android.support.test.espresso.action.ViewActions.click; 30 | import static android.support.test.espresso.assertion.ViewAssertions.matches; 31 | import static android.support.test.espresso.matcher.RootMatchers.withDecorView; 32 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 33 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 34 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 35 | import static org.hamcrest.Matchers.allOf; 36 | import static org.hamcrest.Matchers.is; 37 | import static org.hamcrest.Matchers.not; 38 | import static org.hamcrest.Matchers.startsWith; 39 | 40 | @RunWith(AndroidJUnit4.class) 41 | @LargeTest 42 | public class MainActivityEspressoTest { 43 | 44 | @Rule 45 | public ActivityTestRule mActivityRule = 46 | new ActivityTestRule<>(MainActivity.class); 47 | 48 | @Test 49 | public void testSubscribeAndLog() throws InterruptedException { 50 | onView(withId(R.id.informationTextView)).check(matches(isDisplayed())); 51 | 52 | // Click subscribe button and check toast 53 | onView(allOf(withId(R.id.subscribeButton), withText(R.string.subscribe_to_news))) 54 | .check(matches(isDisplayed())) 55 | .perform(click()); 56 | confirmToastStartsWith(mActivityRule.getActivity().getString(R.string.msg_subscribed)); 57 | 58 | // Sleep so the Toast goes away, this is lazy but it works (Toast.LENGTH_SHORT = 2000) 59 | Thread.sleep(2000); 60 | 61 | // Click log token and check toast 62 | onView(allOf(withId(R.id.logTokenButton), withText(R.string.log_token))) 63 | .check(matches(isDisplayed())) 64 | .perform(click()); 65 | confirmToastStartsWith(mActivityRule.getActivity().getString(R.string.msg_token_fmt, "")); 66 | } 67 | 68 | private void confirmToastStartsWith(String string) { 69 | View activityWindowDecorView = mActivityRule.getActivity().getWindow().getDecorView(); 70 | onView(withText(startsWith(string))) 71 | .inRoot(withDecorView(not(is(activityWindowDecorView)))) 72 | .check(matches(isDisplayed())); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 12 | 13 | 15 | 18 | 20 | 23 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/java/com/google/firebase/quickstart/fcm/MainActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.firebase.quickstart.fcm; 18 | 19 | import android.app.NotificationChannel; 20 | import android.app.NotificationManager; 21 | import android.os.Build; 22 | import android.os.Bundle; 23 | import android.support.annotation.NonNull; 24 | import android.support.v7.app.AppCompatActivity; 25 | import android.util.Log; 26 | import android.view.View; 27 | import android.widget.Button; 28 | import android.widget.Toast; 29 | 30 | import com.google.android.gms.tasks.OnCompleteListener; 31 | import com.google.android.gms.tasks.Task; 32 | import com.google.firebase.iid.FirebaseInstanceId; 33 | import com.google.firebase.iid.InstanceIdResult; 34 | import com.google.firebase.messaging.FirebaseMessaging; 35 | 36 | public class MainActivity extends AppCompatActivity { 37 | 38 | private static final String TAG = "MainActivity"; 39 | 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.activity_main); 44 | 45 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 46 | // Create channel to show notifications. 47 | String channelId = getString(R.string.default_notification_channel_id); 48 | String channelName = getString(R.string.default_notification_channel_name); 49 | NotificationManager notificationManager = 50 | getSystemService(NotificationManager.class); 51 | notificationManager.createNotificationChannel(new NotificationChannel(channelId, 52 | channelName, NotificationManager.IMPORTANCE_LOW)); 53 | } 54 | 55 | // If a notification message is tapped, any data accompanying the notification 56 | // message is available in the intent extras. In this sample the launcher 57 | // intent is fired when the notification is tapped, so any accompanying data would 58 | // be handled here. If you want a different intent fired, set the click_action 59 | // field of the notification message to the desired intent. The launcher intent 60 | // is used when no click_action is specified. 61 | // 62 | // Handle possible data accompanying notification message. 63 | // [START handle_data_extras] 64 | if (getIntent().getExtras() != null) { 65 | for (String key : getIntent().getExtras().keySet()) { 66 | Object value = getIntent().getExtras().get(key); 67 | Log.d(TAG, "Key: " + key + " Value: " + value); 68 | } 69 | } 70 | // [END handle_data_extras] 71 | 72 | Button subscribeButton = findViewById(R.id.subscribeButton); 73 | subscribeButton.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | Log.d(TAG, "Subscribing to news topic"); 77 | // [START subscribe_topics] 78 | FirebaseMessaging.getInstance().subscribeToTopic("news") 79 | .addOnCompleteListener(new OnCompleteListener() { 80 | @Override 81 | public void onComplete(@NonNull Task task) { 82 | String msg = getString(R.string.msg_subscribed); 83 | if (!task.isSuccessful()) { 84 | msg = getString(R.string.msg_subscribe_failed); 85 | } 86 | Log.d(TAG, msg); 87 | Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 88 | } 89 | }); 90 | // [END subscribe_topics] 91 | } 92 | }); 93 | 94 | Button logTokenButton = findViewById(R.id.logTokenButton); 95 | logTokenButton.setOnClickListener(new View.OnClickListener() { 96 | @Override 97 | public void onClick(View v) { 98 | // Get token 99 | FirebaseInstanceId.getInstance().getInstanceId() 100 | .addOnCompleteListener(new OnCompleteListener() { 101 | @Override 102 | public void onComplete(@NonNull Task task) { 103 | if (!task.isSuccessful()) { 104 | Log.w(TAG, "getInstanceId failed", task.getException()); 105 | return; 106 | } 107 | 108 | // Get new Instance ID token 109 | String token = task.getResult().getToken(); 110 | 111 | // Log and toast 112 | String msg = getString(R.string.msg_token_fmt, token); 113 | Log.d(TAG, msg); 114 | Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 115 | } 116 | }); 117 | 118 | 119 | } 120 | }); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/java/com/google/firebase/quickstart/fcm/MyFirebaseMessagingService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.firebase.quickstart.fcm; 18 | 19 | import android.app.NotificationChannel; 20 | import android.app.NotificationManager; 21 | import android.app.PendingIntent; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.media.RingtoneManager; 25 | import android.net.Uri; 26 | import android.os.Build; 27 | import android.support.v4.app.NotificationCompat; 28 | import android.util.Log; 29 | 30 | import com.firebase.jobdispatcher.FirebaseJobDispatcher; 31 | import com.firebase.jobdispatcher.GooglePlayDriver; 32 | import com.firebase.jobdispatcher.Job; 33 | import com.google.firebase.messaging.FirebaseMessagingService; 34 | import com.google.firebase.messaging.RemoteMessage; 35 | 36 | public class MyFirebaseMessagingService extends FirebaseMessagingService { 37 | 38 | private static final String TAG = "MyFirebaseMsgService"; 39 | 40 | /** 41 | * Called when message is received. 42 | * 43 | * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. 44 | */ 45 | // [START receive_message] 46 | @Override 47 | public void onMessageReceived(RemoteMessage remoteMessage) { 48 | // [START_EXCLUDE] 49 | // There are two types of messages data messages and notification messages. Data messages are handled 50 | // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type 51 | // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app 52 | // is in the foreground. When the app is in the background an automatically generated notification is displayed. 53 | // When the user taps on the notification they are returned to the app. Messages containing both notification 54 | // and data payloads are treated as notification messages. The Firebase console always sends notification 55 | // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options 56 | // [END_EXCLUDE] 57 | 58 | // TODO(developer): Handle FCM messages here. 59 | // Not getting messages here? See why this may be: https://goo.gl/39bRNJ 60 | Log.d(TAG, "From: " + remoteMessage.getFrom()); 61 | 62 | // Check if message contains a data payload. 63 | if (remoteMessage.getData().size() > 0) { 64 | Log.d(TAG, "Message data payload: " + remoteMessage.getData()); 65 | 66 | if (/* Check if data needs to be processed by long running job */ true) { 67 | // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher. 68 | scheduleJob(); 69 | } else { 70 | // Handle message within 10 seconds 71 | handleNow(); 72 | } 73 | 74 | } 75 | 76 | // Check if message contains a notification payload. 77 | if (remoteMessage.getNotification() != null) { 78 | Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 79 | } 80 | 81 | sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody()); 82 | } 83 | // [END receive_message] 84 | 85 | 86 | // [START on_new_token] 87 | /** 88 | * Called if InstanceID token is updated. This may occur if the security of 89 | * the previous token had been compromised. Note that this is called when the InstanceID token 90 | * is initially generated so this is where you would retrieve the token. 91 | */ 92 | @Override 93 | public void onNewToken(String token) { 94 | Log.d(TAG, "Refreshed token: " + token); 95 | 96 | // If you want to send messages to this application instance or 97 | // manage this apps subscriptions on the server side, send the 98 | // Instance ID token to your app server. 99 | sendRegistrationToServer(token); 100 | } 101 | // [END on_new_token] 102 | 103 | /** 104 | * Schedule a job using FirebaseJobDispatcher. 105 | */ 106 | private void scheduleJob() { 107 | // [START dispatch_job] 108 | FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this)); 109 | Job myJob = dispatcher.newJobBuilder() 110 | .setService(MyJobService.class) 111 | .setTag("my-job-tag") 112 | .build(); 113 | dispatcher.schedule(myJob); 114 | // [END dispatch_job] 115 | } 116 | 117 | /** 118 | * Handle time allotted to BroadcastReceivers. 119 | */ 120 | private void handleNow() { 121 | Log.d(TAG, "Short lived task is done."); 122 | } 123 | 124 | /** 125 | * Persist token to third-party servers. 126 | * 127 | * Modify this method to associate the user's FCM InstanceID token with any server-side account 128 | * maintained by your application. 129 | * 130 | * @param token The new token. 131 | */ 132 | private void sendRegistrationToServer(String token) { 133 | // TODO: Implement this method to send token to your app server. 134 | } 135 | 136 | private void sendNotification(String title, String body) { 137 | Intent intent = new Intent(this, MainActivity.class); 138 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 139 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 140 | PendingIntent.FLAG_ONE_SHOT); 141 | 142 | String channelId = getString(R.string.default_notification_channel_id); 143 | Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 144 | NotificationCompat.Builder notificationBuilder = 145 | new NotificationCompat.Builder(this, channelId) 146 | .setSmallIcon(R.drawable.ic_stat_ic_notification) 147 | .setContentTitle(title) 148 | .setContentText(body) 149 | .setAutoCancel(true) 150 | .setSound(defaultSoundUri) 151 | .setContentIntent(pendingIntent); 152 | 153 | NotificationManager notificationManager = 154 | (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 155 | 156 | // Since android Oreo notification channel is needed. 157 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 158 | NotificationChannel channel = new NotificationChannel(channelId, 159 | "Channel human readable title", 160 | NotificationManager.IMPORTANCE_DEFAULT); 161 | notificationManager.createNotificationChannel(channel); 162 | } 163 | 164 | notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/java/com/google/firebase/quickstart/fcm/MyJobService.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.quickstart.fcm; 2 | 3 | import android.util.Log; 4 | 5 | import com.firebase.jobdispatcher.JobParameters; 6 | import com.firebase.jobdispatcher.JobService; 7 | 8 | public class MyJobService extends JobService { 9 | 10 | private static final String TAG = "MyJobService"; 11 | 12 | @Override 13 | public boolean onStartJob(JobParameters jobParameters) { 14 | Log.d(TAG, "Performing long running task in scheduled job"); 15 | // TODO(developer): add long running task here. 16 | return false; 17 | } 18 | 19 | @Override 20 | public boolean onStopJob(JobParameters jobParameters) { 21 | return false; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi-v11/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi-v11/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi/firebase_lockup_400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi/firebase_lockup_400.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-hdpi/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi-v11/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi-v11/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi/firebase_lockup_400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi/firebase_lockup_400.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-mdpi/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi-v11/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi-v11/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi/firebase_lockup_400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi/firebase_lockup_400.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xhdpi/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi-v11/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi-v11/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi/firebase_lockup_400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi/firebase_lockup_400.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxhdpi/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxxhdpi-v11/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxxhdpi-v11/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxxhdpi/ic_stat_ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytefish/FcmSharp/20bbdcb4f69ee521511efea7ec48b10f130d701a/FcmSharp/Examples/Android/messaging-app/app/src/main/res/drawable-xxxhdpi/ic_stat_ic_notification.png -------------------------------------------------------------------------------- /FcmSharp/Examples/Android/messaging-app/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 18 | 19 | 26 | 27 |