Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-fcm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
react-native-fcm
Commits
ace93202
Commit
ace93202
authored
Oct 03, 2016
by
Lukas Benes
Committed by
Libin Lu
Oct 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upstream messages support (#132)
parent
709b60df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
...rc/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+35
-1
index.js
index.js
+4
-0
No files found.
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
View file @
ace93202
...
...
@@ -13,6 +13,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
import
com.facebook.react.bridge.ReactMethod
;
import
com.facebook.react.bridge.ReadableMap
;
import
com.facebook.react.bridge.ReadableMapKeySetIterator
;
import
com.facebook.react.bridge.WritableArray
;
import
com.facebook.react.bridge.WritableMap
;
import
com.facebook.react.modules.core.DeviceEventManagerModule
;
...
...
@@ -29,11 +30,12 @@ import android.content.Context;
import
java.util.ArrayList
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
public
class
FIRMessagingModule
extends
ReactContextBaseJavaModule
implements
LifecycleEventListener
,
ActivityEventListener
{
private
final
static
String
TAG
=
FIRMessagingModule
.
class
.
getCanonicalName
();
private
FIRLocalMessagingHelper
mFIRLocalMessagingHelper
;
public
FIRMessagingModule
(
ReactApplicationContext
reactContext
)
{
super
(
reactContext
);
mFIRLocalMessagingHelper
=
new
FIRLocalMessagingHelper
((
Application
)
reactContext
.
getApplicationContext
());
...
...
@@ -131,6 +133,38 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
},
intentFilter
);
}
@ReactMethod
public
void
send
(
String
senderId
,
ReadableMap
payload
)
throws
Exception
{
FirebaseMessaging
fm
=
FirebaseMessaging
.
getInstance
();
RemoteMessage
.
Builder
message
=
new
RemoteMessage
.
Builder
(
senderId
+
"@gcm.googleapis.com"
)
.
setMessageId
(
UUID
.
randomUUID
().
toString
());
ReadableMapKeySetIterator
iterator
=
payload
.
keySetIterator
();
while
(
iterator
.
hasNextKey
())
{
String
key
=
iterator
.
nextKey
();
String
value
=
getStringFromReadableMap
(
payload
,
key
);
message
.
addData
(
key
,
value
);
}
fm
.
send
(
message
.
build
());
}
private
String
getStringFromReadableMap
(
ReadableMap
map
,
String
key
)
throws
Exception
{
switch
(
map
.
getType
(
key
))
{
case
String:
return
map
.
getString
(
key
);
case
Number:
try
{
return
String
.
valueOf
(
map
.
getInt
(
key
));
}
catch
(
Exception
e
)
{
return
String
.
valueOf
(
map
.
getDouble
(
key
));
}
case
Boolean:
return
String
.
valueOf
(
map
.
getBoolean
(
key
));
default
:
throw
new
Exception
(
"Unknown data type: "
+
map
.
getType
(
key
).
name
()
+
" for message key "
+
key
);
}
}
private
void
registerMessageHandler
()
{
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveNotification"
);
...
...
index.js
View file @
ace93202
...
...
@@ -74,4 +74,8 @@ FCM.unsubscribeFromTopic = (topic) => {
RNFIRMessaging
.
unsubscribeFromTopic
(
topic
);
};
FCM
.
send
=
(
senderId
,
payload
)
=>
{
RNFIRMessaging
.
send
(
senderId
,
payload
);
};
module
.
exports
=
FCM
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment