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
7daac877
Commit
7daac877
authored
Sep 20, 2016
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not show scheduled notification if app is foreground
parent
6a790a4a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
26 deletions
+55
-26
android/react-native-fcm.iml
android/react-native-fcm.iml
+1
-1
android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java
...in/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java
+34
-24
android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingPublisher.java
...java/com/evollu/react/fcm/FIRLocalMessagingPublisher.java
+0
-1
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
...rc/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+17
-0
index.js
index.js
+3
-0
No files found.
android/react-native-fcm.iml
View file @
7daac877
...
@@ -120,8 +120,8 @@
...
@@ -120,8 +120,8 @@
<orderEntry
type=
"library"
exported=
""
name=
"firebase-iid-9.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"firebase-iid-9.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"okio-1.9.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"okio-1.9.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"jsr305-3.0.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"jsr305-3.0.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"okhttp-3.4.1"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"bolts-tasks-1.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"bolts-tasks-1.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"okhttp-3.4.1"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"firebase-common-9.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"firebase-common-9.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"appcompat-v7-23.0.1"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"appcompat-v7-23.0.1"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"firebase-core-9.4.0"
level=
"project"
/>
<orderEntry
type=
"library"
exported=
""
name=
"firebase-core-9.4.0"
level=
"project"
/>
...
...
android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java
View file @
7daac877
...
@@ -27,6 +27,7 @@ public class FIRLocalMessagingHelper {
...
@@ -27,6 +27,7 @@ public class FIRLocalMessagingHelper {
private
static
final
long
DEFAULT_VIBRATION
=
300L
;
private
static
final
long
DEFAULT_VIBRATION
=
300L
;
private
static
final
String
TAG
=
FIRLocalMessagingHelper
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
FIRLocalMessagingHelper
.
class
.
getSimpleName
();
private
final
static
String
PREFERENCES_KEY
=
"ReactNativeSystemNotification"
;
private
final
static
String
PREFERENCES_KEY
=
"ReactNativeSystemNotification"
;
private
static
boolean
mIsForeground
=
false
;
//this is a hack
private
Context
mContext
;
private
Context
mContext
;
private
SharedPreferences
sharedPreferences
=
null
;
private
SharedPreferences
sharedPreferences
=
null
;
...
@@ -149,31 +150,36 @@ public class FIRLocalMessagingHelper {
...
@@ -149,31 +150,36 @@ public class FIRLocalMessagingHelper {
}
}
}
}
if
(
mIsForeground
){
Intent
intent
=
new
Intent
(
mContext
,
intentClass
);
Log
.
d
(
TAG
,
"App is in foreground, broadcast intent instead"
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
Intent
i
=
new
Intent
(
"com.evollu.react.fcm.ReceiveLocalNotification"
);
intent
.
putExtra
(
"notification"
,
bundle
);
i
.
putExtras
(
bundle
);
intent
.
putExtra
(
"localNotification"
,
true
);
mContext
.
sendOrderedBroadcast
(
i
,
null
);
intent
.
setAction
(
bundle
.
getString
(
"click_action"
));
}
else
{
Intent
intent
=
new
Intent
(
mContext
,
intentClass
);
int
notificationID
=
bundle
.
containsKey
(
"id"
)
?
bundle
.
getString
(
"id"
,
""
).
hashCode
()
:
(
int
)
System
.
currentTimeMillis
();
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
intent
,
intent
.
putExtras
(
bundle
);
PendingIntent
.
FLAG_UPDATE_CURRENT
);
intent
.
putExtra
(
"localNotification"
,
true
);
intent
.
setAction
(
bundle
.
getString
(
"click_action"
));
NotificationManager
notificationManager
=
(
NotificationManager
)
mContext
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
notificationID
=
bundle
.
containsKey
(
"id"
)
?
bundle
.
getString
(
"id"
,
""
).
hashCode
()
:
(
int
)
System
.
currentTimeMillis
();
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
intent
,
notification
.
setContentIntent
(
pendingIntent
);
PendingIntent
.
FLAG_UPDATE_CURRENT
);
Notification
info
=
notification
.
build
();
NotificationManager
notificationManager
=
(
NotificationManager
)
mContext
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
if
(
bundle
.
containsKey
(
"tag"
))
{
String
tag
=
bundle
.
getString
(
"tag"
);
notification
.
setContentIntent
(
pendingIntent
);
notificationManager
.
notify
(
tag
,
notificationID
,
info
);
}
else
{
Notification
info
=
notification
.
build
();
notificationManager
.
notify
(
notificationID
,
info
);
if
(
bundle
.
containsKey
(
"tag"
))
{
String
tag
=
bundle
.
getString
(
"tag"
);
notificationManager
.
notify
(
tag
,
notificationID
,
info
);
}
else
{
notificationManager
.
notify
(
notificationID
,
info
);
}
}
}
//clear out one time scheduled notification once fired
//clear out one time scheduled notification once fired
if
(!
bundle
.
containsKey
(
"repeat_interval"
)
&&
bundle
.
containsKey
(
"fire_date"
))
{
if
(!
bundle
.
containsKey
(
"repeat_interval"
)
&&
bundle
.
containsKey
(
"fire_date"
))
{
SharedPreferences
.
Editor
editor
=
sharedPreferences
.
edit
();
SharedPreferences
.
Editor
editor
=
sharedPreferences
.
edit
();
...
@@ -291,4 +297,8 @@ public class FIRLocalMessagingHelper {
...
@@ -291,4 +297,8 @@ public class FIRLocalMessagingHelper {
}
}
return
array
;
return
array
;
}
}
public
void
setApplicationForeground
(
boolean
foreground
){
mIsForeground
=
foreground
;
}
}
}
android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingPublisher.java
View file @
7daac877
...
@@ -4,7 +4,6 @@ import android.app.Application;
...
@@ -4,7 +4,6 @@ import android.app.Application;
import
android.content.BroadcastReceiver
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.util.Log
;
public
class
FIRLocalMessagingPublisher
extends
BroadcastReceiver
{
public
class
FIRLocalMessagingPublisher
extends
BroadcastReceiver
{
...
...
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
View file @
7daac877
...
@@ -41,6 +41,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -41,6 +41,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
getReactApplicationContext
().
addActivityEventListener
(
this
);
getReactApplicationContext
().
addActivityEventListener
(
this
);
registerTokenRefreshHandler
();
registerTokenRefreshHandler
();
registerMessageHandler
();
registerMessageHandler
();
registerLocalMessageHandler
();
}
}
@Override
@Override
...
@@ -149,6 +150,20 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -149,6 +150,20 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
},
intentFilter
);
},
intentFilter
);
}
}
private
void
registerLocalMessageHandler
()
{
IntentFilter
intentFilter
=
new
IntentFilter
(
"com.evollu.react.fcm.ReceiveLocalNotification"
);
getReactApplicationContext
().
registerReceiver
(
new
BroadcastReceiver
()
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
if
(
getReactApplicationContext
().
hasActiveCatalystInstance
())
{
sendEvent
(
"FCMLocalNotificationReceived"
,
Arguments
.
fromBundle
(
intent
.
getExtras
()));
abortBroadcast
();
}
}
},
intentFilter
);
}
private
WritableMap
parseIntent
(
Intent
intent
){
private
WritableMap
parseIntent
(
Intent
intent
){
WritableMap
params
;
WritableMap
params
;
Bundle
extras
=
intent
.
getExtras
();
Bundle
extras
=
intent
.
getExtras
();
...
@@ -172,10 +187,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -172,10 +187,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
@Override
@Override
public
void
onHostResume
()
{
public
void
onHostResume
()
{
mFIRLocalMessagingHelper
.
setApplicationForeground
(
true
);
}
}
@Override
@Override
public
void
onHostPause
()
{
public
void
onHostPause
()
{
mFIRLocalMessagingHelper
.
setApplicationForeground
(
false
);
}
}
@Override
@Override
...
...
index.js
View file @
7daac877
...
@@ -27,6 +27,9 @@ FCM.presentLocalNotification = (details) => {
...
@@ -27,6 +27,9 @@ FCM.presentLocalNotification = (details) => {
};
};
FCM
.
scheduleLocalNotification
=
function
(
details
)
{
FCM
.
scheduleLocalNotification
=
function
(
details
)
{
if
(
!
details
.
id
)
{
throw
new
Error
(
"
id is required for scheduled notification
"
);
}
RNFIRMessaging
.
scheduleLocalNotification
(
details
);
RNFIRMessaging
.
scheduleLocalNotification
(
details
);
};
};
...
...
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