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
ca7143a4
Commit
ca7143a4
authored
Sep 27, 2017
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bump version
parent
de31a2c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
37 deletions
+38
-37
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
...rc/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+37
-36
package.json
package.json
+1
-1
No files found.
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
View file @
ca7143a4
...
@@ -38,7 +38,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -38,7 +38,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
private
final
static
String
TAG
=
FIRMessagingModule
.
class
.
getCanonicalName
();
private
final
static
String
TAG
=
FIRMessagingModule
.
class
.
getCanonicalName
();
private
FIRLocalMessagingHelper
mFIRLocalMessagingHelper
;
private
FIRLocalMessagingHelper
mFIRLocalMessagingHelper
;
private
BadgeHelper
mBadgeHelper
;
private
BadgeHelper
mBadgeHelper
;
public
FIRMessagingModule
(
ReactApplicationContext
reactContext
)
{
public
FIRMessagingModule
(
ReactApplicationContext
reactContext
)
{
super
(
reactContext
);
super
(
reactContext
);
mFIRLocalMessagingHelper
=
new
FIRLocalMessagingHelper
((
Application
)
reactContext
.
getApplicationContext
());
mFIRLocalMessagingHelper
=
new
FIRLocalMessagingHelper
((
Application
)
reactContext
.
getApplicationContext
());
...
@@ -49,12 +49,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -49,12 +49,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
registerMessageHandler
();
registerMessageHandler
();
registerLocalMessageHandler
();
registerLocalMessageHandler
();
}
}
@Override
@Override
public
String
getName
()
{
public
String
getName
()
{
return
"RNFIRMessaging"
;
return
"RNFIRMessaging"
;
}
}
@ReactMethod
@ReactMethod
public
void
getInitialNotification
(
Promise
promise
){
public
void
getInitialNotification
(
Promise
promise
){
Activity
activity
=
getCurrentActivity
();
Activity
activity
=
getCurrentActivity
();
...
@@ -65,7 +65,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -65,7 +65,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
promise
.
resolve
(
parseIntent
(
activity
.
getIntent
()));
promise
.
resolve
(
parseIntent
(
activity
.
getIntent
()));
}
}
@ReactMethod
@ReactMethod
public
void
requestPermissions
(
Promise
promise
){
public
void
requestPermissions
(
Promise
promise
){
if
(
NotificationManagerCompat
.
from
(
getReactApplicationContext
()).
areNotificationsEnabled
()){
if
(
NotificationManagerCompat
.
from
(
getReactApplicationContext
()).
areNotificationsEnabled
()){
...
@@ -74,7 +74,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -74,7 +74,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise
.
reject
(
null
,
"Notification disabled"
);
promise
.
reject
(
null
,
"Notification disabled"
);
}
}
}
}
@ReactMethod
@ReactMethod
public
void
getFCMToken
(
Promise
promise
)
{
public
void
getFCMToken
(
Promise
promise
)
{
try
{
try
{
...
@@ -85,7 +85,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -85,7 +85,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise
.
reject
(
null
,
e
.
getMessage
());
promise
.
reject
(
null
,
e
.
getMessage
());
}
}
}
}
@ReactMethod
@ReactMethod
public
void
deleteInstanceId
(
Promise
promise
){
public
void
deleteInstanceId
(
Promise
promise
){
try
{
try
{
...
@@ -96,19 +96,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -96,19 +96,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise
.
reject
(
null
,
e
.
getMessage
());
promise
.
reject
(
null
,
e
.
getMessage
());
}
}
}
}
@ReactMethod
@ReactMethod
public
void
presentLocalNotification
(
ReadableMap
details
)
{
public
void
presentLocalNotification
(
ReadableMap
details
)
{
Bundle
bundle
=
Arguments
.
toBundle
(
details
);
Bundle
bundle
=
Arguments
.
toBundle
(
details
);
mFIRLocalMessagingHelper
.
sendNotification
(
bundle
);
mFIRLocalMessagingHelper
.
sendNotification
(
bundle
);
}
}
@ReactMethod
@ReactMethod
public
void
scheduleLocalNotification
(
ReadableMap
details
)
{
public
void
scheduleLocalNotification
(
ReadableMap
details
)
{
Bundle
bundle
=
Arguments
.
toBundle
(
details
);
Bundle
bundle
=
Arguments
.
toBundle
(
details
);
mFIRLocalMessagingHelper
.
sendNotificationScheduled
(
bundle
);
mFIRLocalMessagingHelper
.
sendNotificationScheduled
(
bundle
);
}
}
@ReactMethod
@ReactMethod
public
void
cancelLocalNotification
(
String
notificationID
)
{
public
void
cancelLocalNotification
(
String
notificationID
)
{
mFIRLocalMessagingHelper
.
cancelLocalNotification
(
notificationID
);
mFIRLocalMessagingHelper
.
cancelLocalNotification
(
notificationID
);
...
@@ -117,27 +117,27 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -117,27 +117,27 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
public
void
cancelAllLocalNotifications
()
{
public
void
cancelAllLocalNotifications
()
{
mFIRLocalMessagingHelper
.
cancelAllLocalNotifications
();
mFIRLocalMessagingHelper
.
cancelAllLocalNotifications
();
}
}
@ReactMethod
@ReactMethod
public
void
removeDeliveredNotification
(
String
notificationID
)
{
public
void
removeDeliveredNotification
(
String
notificationID
)
{
mFIRLocalMessagingHelper
.
removeDeliveredNotification
(
notificationID
);
mFIRLocalMessagingHelper
.
removeDeliveredNotification
(
notificationID
);
}
}
@ReactMethod
@ReactMethod
public
void
removeAllDeliveredNotifications
(){
public
void
removeAllDeliveredNotifications
(){
mFIRLocalMessagingHelper
.
removeAllDeliveredNotifications
();
mFIRLocalMessagingHelper
.
removeAllDeliveredNotifications
();
}
}
@ReactMethod
@ReactMethod
public
void
subscribeToTopic
(
String
topic
){
public
void
subscribeToTopic
(
String
topic
){
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
);
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
);
}
}
@ReactMethod
@ReactMethod
public
void
unsubscribeFromTopic
(
String
topic
){
public
void
unsubscribeFromTopic
(
String
topic
){
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
);
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
);
}
}
@ReactMethod
@ReactMethod
public
void
getScheduledLocalNotifications
(
Promise
promise
){
public
void
getScheduledLocalNotifications
(
Promise
promise
){
ArrayList
<
Bundle
>
bundles
=
mFIRLocalMessagingHelper
.
getScheduledLocalNotifications
();
ArrayList
<
Bundle
>
bundles
=
mFIRLocalMessagingHelper
.
getScheduledLocalNotifications
();
...
@@ -147,23 +147,23 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -147,23 +147,23 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
promise
.
resolve
(
array
);
promise
.
resolve
(
array
);
}
}
@ReactMethod
@ReactMethod
public
void
setBadgeNumber
(
int
badgeNumber
)
{
public
void
setBadgeNumber
(
int
badgeNumber
)
{
mBadgeHelper
.
setBadgeCount
(
badgeNumber
);
mBadgeHelper
.
setBadgeCount
(
badgeNumber
);
}
}
@ReactMethod
@ReactMethod
public
void
getBadgeNumber
(
Promise
promise
)
{
public
void
getBadgeNumber
(
Promise
promise
)
{
promise
.
resolve
(
mBadgeHelper
.
getBadgeCount
());
promise
.
resolve
(
mBadgeHelper
.
getBadgeCount
());
}
}
private
void
sendEvent
(
String
eventName
,
Object
params
)
{
private
void
sendEvent
(
String
eventName
,
Object
params
)
{
getReactApplicationContext
()
getReactApplicationContext
()
.
getJSModule
(
DeviceEventManagerModule
.
RCTDeviceEventEmitter
.
class
)
.
getJSModule
(
DeviceEventManagerModule
.
RCTDeviceEventEmitter
.
class
)
.
emit
(
eventName
,
params
);
.
emit
(
eventName
,
params
);
}
}
private
void
registerTokenRefreshHandler
()
{
private
void
registerTokenRefreshHandler
()
{
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.FCMRefreshToken"
);
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.FCMRefreshToken"
);
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
...
@@ -176,13 +176,13 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -176,13 +176,13 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
},
intentFilter
);
},
intentFilter
);
}
}
@ReactMethod
@ReactMethod
public
void
send
(
String
senderId
,
ReadableMap
payload
)
throws
Exception
{
public
void
send
(
String
senderId
,
ReadableMap
payload
)
throws
Exception
{
FirebaseMessaging
fm
=
FirebaseMessaging
.
getInstance
();
FirebaseMessaging
fm
=
FirebaseMessaging
.
getInstance
();
RemoteMessage
.
Builder
message
=
new
RemoteMessage
.
Builder
(
senderId
+
"@gcm.googleapis.com"
)
RemoteMessage
.
Builder
message
=
new
RemoteMessage
.
Builder
(
senderId
+
"@gcm.googleapis.com"
)
.
setMessageId
(
UUID
.
randomUUID
().
toString
());
.
setMessageId
(
UUID
.
randomUUID
().
toString
());
ReadableMapKeySetIterator
iterator
=
payload
.
keySetIterator
();
ReadableMapKeySetIterator
iterator
=
payload
.
keySetIterator
();
while
(
iterator
.
hasNextKey
())
{
while
(
iterator
.
hasNextKey
())
{
String
key
=
iterator
.
nextKey
();
String
key
=
iterator
.
nextKey
();
...
@@ -191,7 +191,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -191,7 +191,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
fm
.
send
(
message
.
build
());
fm
.
send
(
message
.
build
());
}
}
private
String
getStringFromReadableMap
(
ReadableMap
map
,
String
key
)
throws
Exception
{
private
String
getStringFromReadableMap
(
ReadableMap
map
,
String
key
)
throws
Exception
{
switch
(
map
.
getType
(
key
))
{
switch
(
map
.
getType
(
key
))
{
case
String:
case
String:
...
@@ -208,10 +208,10 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -208,10 +208,10 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
throw
new
Exception
(
"Unknown data type: "
+
map
.
getType
(
key
).
name
()
+
" for message key "
+
key
);
throw
new
Exception
(
"Unknown data type: "
+
map
.
getType
(
key
).
name
()
+
" for message key "
+
key
);
}
}
}
}
private
void
registerMessageHandler
()
{
private
void
registerMessageHandler
()
{
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveNotification"
);
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveNotification"
);
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
@Override
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
...
@@ -219,7 +219,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -219,7 +219,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
RemoteMessage
message
=
intent
.
getParcelableExtra
(
"data"
);
RemoteMessage
message
=
intent
.
getParcelableExtra
(
"data"
);
WritableMap
params
=
Arguments
.
createMap
();
WritableMap
params
=
Arguments
.
createMap
();
WritableMap
fcmData
=
Arguments
.
createMap
();
WritableMap
fcmData
=
Arguments
.
createMap
();
if
(
message
.
getNotification
()
!=
null
)
{
if
(
message
.
getNotification
()
!=
null
)
{
Notification
notification
=
message
.
getNotification
();
Notification
notification
=
message
.
getNotification
();
fcmData
.
putString
(
"title"
,
notification
.
getTitle
());
fcmData
.
putString
(
"title"
,
notification
.
getTitle
());
...
@@ -234,7 +234,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -234,7 +234,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
params
.
putString
(
"from"
,
message
.
getFrom
());
params
.
putString
(
"from"
,
message
.
getFrom
());
params
.
putString
(
"google.message_id"
,
message
.
getMessageId
());
params
.
putString
(
"google.message_id"
,
message
.
getMessageId
());
params
.
putDouble
(
"google.sent_time"
,
message
.
getSentTime
());
params
.
putDouble
(
"google.sent_time"
,
message
.
getSentTime
());
if
(
message
.
getData
()
!=
null
){
if
(
message
.
getData
()
!=
null
){
Map
<
String
,
String
>
data
=
message
.
getData
();
Map
<
String
,
String
>
data
=
message
.
getData
();
Set
<
String
>
keysIterator
=
data
.
keySet
();
Set
<
String
>
keysIterator
=
data
.
keySet
();
...
@@ -243,15 +243,15 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -243,15 +243,15 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
}
}
sendEvent
(
"FCMNotificationReceived"
,
params
);
sendEvent
(
"FCMNotificationReceived"
,
params
);
}
}
}
}
},
intentFilter
);
},
intentFilter
);
}
}
private
void
registerLocalMessageHandler
()
{
private
void
registerLocalMessageHandler
()
{
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveLocalNotification"
);
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveLocalNotification"
);
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
@Override
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
...
@@ -261,7 +261,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -261,7 +261,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
},
intentFilter
);
},
intentFilter
);
}
}
private
WritableMap
parseIntent
(
Intent
intent
){
private
WritableMap
parseIntent
(
Intent
intent
){
WritableMap
params
;
WritableMap
params
;
Bundle
extras
=
intent
.
getExtras
();
Bundle
extras
=
intent
.
getExtras
();
...
@@ -278,30 +278,30 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -278,30 +278,30 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
WritableMap
fcm
=
Arguments
.
createMap
();
WritableMap
fcm
=
Arguments
.
createMap
();
fcm
.
putString
(
"action"
,
intent
.
getAction
());
fcm
.
putString
(
"action"
,
intent
.
getAction
());
params
.
putMap
(
"fcm"
,
fcm
);
params
.
putMap
(
"fcm"
,
fcm
);
params
.
putInt
(
"opened_from_tray"
,
1
);
params
.
putInt
(
"opened_from_tray"
,
1
);
return
params
;
return
params
;
}
}
@Override
@Override
public
void
onHostResume
()
{
public
void
onHostResume
()
{
mFIRLocalMessagingHelper
.
setApplicationForeground
(
true
);
mFIRLocalMessagingHelper
.
setApplicationForeground
(
true
);
}
}
@Override
@Override
public
void
onHostPause
()
{
public
void
onHostPause
()
{
mFIRLocalMessagingHelper
.
setApplicationForeground
(
false
);
mFIRLocalMessagingHelper
.
setApplicationForeground
(
false
);
}
}
@Override
@Override
public
void
onHostDestroy
()
{
public
void
onHostDestroy
()
{
}
}
@Override
@Override
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
Intent
data
)
{
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
Intent
data
)
{
}
}
@Override
@Override
public
void
onNewIntent
(
Intent
intent
){
public
void
onNewIntent
(
Intent
intent
){
// don't call notification if it is started from icon
// don't call notification if it is started from icon
...
@@ -311,3 +311,4 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -311,3 +311,4 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
sendEvent
(
"FCMNotificationReceived"
,
parseIntent
(
intent
));
sendEvent
(
"FCMNotificationReceived"
,
parseIntent
(
intent
));
}
}
}
}
package.json
View file @
ca7143a4
...
@@ -24,5 +24,5 @@
...
@@ -24,5 +24,5 @@
"type"
:
"git"
,
"type"
:
"git"
,
"url"
:
"git+https://github.com/evollu/react-native-fcm.git"
"url"
:
"git+https://github.com/evollu/react-native-fcm.git"
},
},
"version"
:
"9.6.
0
"
"version"
:
"9.6.
1
"
}
}
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