This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//RecyclerView | |
compile 'com.android.support:recyclerview-v7:26.+' | |
//Firebase Authentication | |
compile 'com.google.firebase:firebase-auth:11.4.0' | |
//Firebase Realtime Database | |
compile 'com.google.firebase:firebase-database:11.4.0' | |
//Firebase Cloud Messaging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//url | |
https://fcm.googleapis.com/fcm/send | |
//headers | |
Authorization: <Your Server Key> | |
Content-Type: application/json | |
//body | |
{ | |
"to" : "< user FCM token >", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void sendRegistrationToServer(String token) { | |
Log.d(TAG, "sendRegistrationToServer: sending token to server: " + token); | |
DatabaseReference reference = FirebaseDatabase.getInstance().getReference(); | |
reference.child(getString(R.string.dbnode_users)) | |
.child(FirebaseAuth.getInstance().getCurrentUser().getUid()) | |
.child(getString(R.string.field_messaging_token)) | |
.setValue(token); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { | |
private static final String TAG = "MyFirebaseIIDService"; | |
/** | |
* Called if InstanceID token is updated. This may occur if the security of | |
* the previous token had been compromised. Note that this is called when the InstanceID token | |
* is initially generated so this is where you would retrieve the token. | |
*/ | |
@Override | |
public void onTokenRefresh() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyFirebaseMessagingService extends FirebaseMessagingService { | |
private static final String TAG = "MyFirebaseMsgService"; | |
private static final int BROADCAST_NOTIFICATION_ID = 1; | |
@Override | |
public void onDeletedMessages() { | |
super.onDeletedMessages(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<service | |
android:name=".utility.MyFirebaseMessagingService"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let functions = require('firebase-functions'); | |
let admin = require('firebase-admin'); | |
admin.initializeApp(functions.config().firebase); | |
exports.sendNotification = functions.database.ref('/messages/{userId}/{messageId}').onWrite(event => { | |
//get the userId of the person receiving the notification because we need to get their token | |
const receiverId = event.params.userId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:2.3.3' | |
classpath 'com.google.gms:google-services:3.1.0' | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 26 | |
buildToolsVersion "27.0.1" | |
defaultConfig { | |
applicationId "codingwithmitch.com.firebasedirectmessage" | |
minSdkVersion 16 | |
targetSdkVersion 26 | |
versionCode 1 |