Skip to content

Instantly share code, notes, and snippets.

View mitchtabian's full-sized avatar
🎞️
Building stuff

Mitch Tabian mitchtabian

🎞️
Building stuff
View GitHub Profile
//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
//url
https://fcm.googleapis.com/fcm/send
//headers
Authorization: <Your Server Key>
Content-Type: application/json
//body
{
"to" : "< user FCM token >",
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);
}
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() {
<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
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();
}
<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">
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;
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
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "codingwithmitch.com.firebasedirectmessage"
minSdkVersion 16
targetSdkVersion 26
versionCode 1