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
cb2c6ccf
Commit
cb2c6ccf
authored
Jun 13, 2018
by
Libin Lu
Committed by
GitHub
Jun 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #699 from evollu/sdk-26
add channel
parents
6dbffd50
e7f0ad93
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
84 additions
and
11 deletions
+84
-11
Examples/simple-fcm-client/android/app/build.gradle
Examples/simple-fcm-client/android/app/build.gradle
+7
-3
Examples/simple-fcm-client/android/build.gradle
Examples/simple-fcm-client/android/build.gradle
+10
-2
Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties
...m-client/android/gradle/wrapper/gradle-wrapper.properties
+2
-2
Examples/simple-fcm-client/app/App.js
Examples/simple-fcm-client/app/App.js
+7
-0
android/build.gradle
android/build.gradle
+4
-3
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
...rc/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+47
-0
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
.../main/java/com/evollu/react/fcm/SendNotificationTask.java
+1
-1
index.js
index.js
+6
-0
No files found.
Examples/simple-fcm-client/android/app/build.gradle
View file @
cb2c6ccf
...
...
@@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false
def
enableProguardInReleaseBuilds
=
false
android
{
compileSdkVersion
2
3
buildToolsVersion
"2
3.0.1
"
compileSdkVersion
2
7
buildToolsVersion
"2
7.0.3
"
defaultConfig
{
applicationId
"com.google.firebase.quickstart.fcm"
minSdkVersion
16
targetSdkVersion
2
2
targetSdkVersion
2
7
versionCode
1
versionName
"1.0"
ndk
{
...
...
@@ -123,6 +123,10 @@ android {
}
}
}
configurations
.
all
{
resolutionStrategy
.
force
'com.android.support:support-core-utils:26.1.0'
resolutionStrategy
.
force
'com.android.support:support-core-ui:26.1.0'
}
}
dependencies
{
...
...
Examples/simple-fcm-client/android/build.gradle
View file @
cb2c6ccf
...
...
@@ -3,10 +3,14 @@
buildscript
{
repositories
{
jcenter
()
maven
{
url
'https://maven.google.com/'
name
'Google'
}
}
dependencies
{
classpath
'com.android.tools.build:gradle:
2.2.3
'
classpath
'com.google.gms:google-services:3.
0.0
'
classpath
'com.android.tools.build:gradle:
3.1.1
'
classpath
'com.google.gms:google-services:3.
1.2
'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
...
...
@@ -21,5 +25,9 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url
"$rootDir/../node_modules/react-native/android"
}
maven
{
url
'https://maven.google.com/'
name
'Google'
}
}
}
Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties
View file @
cb2c6ccf
#
Fri Jan 06 16:34:59 EST 2017
#
Thu May 03 13:49:29 EDT 2018
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
2.14.1
-all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
4.4
-all.zip
Examples/simple-fcm-client/app/App.js
View file @
cb2c6ccf
...
...
@@ -35,6 +35,12 @@ class MainPage extends Component {
}
async
componentDidMount
()
{
FCM
.
createNotificationChannel
({
id
:
'
default
'
,
name
:
'
Default
'
,
description
:
'
used for example
'
,
priority
:
'
high
'
})
registerAppListener
(
this
.
props
.
navigation
);
FCM
.
getInitialNotification
().
then
(
notif
=>
{
this
.
setState
({
...
...
@@ -75,6 +81,7 @@ class MainPage extends Component {
showLocalNotification
()
{
FCM
.
presentLocalNotification
({
channel
:
'
default
'
,
id
:
new
Date
().
valueOf
().
toString
(),
// (optional for instant notification)
title
:
"
Test Notification with action
"
,
// as FCM payload
body
:
"
Force touch to reply
"
,
// as FCM payload (required)
...
...
android/build.gradle
View file @
cb2c6ccf
apply
plugin:
'com.android.library'
def
DEFAULT_COMPILE_SDK_VERSION
=
2
5
def
DEFAULT_COMPILE_SDK_VERSION
=
2
6
def
DEFAULT_BUILD_TOOLS_VERSION
=
"25.0.2"
def
DEFAULT_TARGET_SDK_VERSION
=
2
5
def
DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
=
"1
1
.+"
def
DEFAULT_TARGET_SDK_VERSION
=
2
6
def
DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
=
"1
2
.+"
android
{
compileSdkVersion
project
.
hasProperty
(
'compileSdkVersion'
)
?
project
.
compileSdkVersion
:
DEFAULT_COMPILE_SDK_VERSION
...
...
@@ -29,5 +29,6 @@ dependencies {
compile
"com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile
"com.google.firebase:firebase-messaging:$googlePlayServicesVersion"
compile
'me.leolin:ShortcutBadger:1.1.17@aar'
compile
"com.android.support:support-core-utils:26.1.0"
}
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
View file @
cb2c6ccf
package
com.evollu.react.fcm
;
import
android.app.Activity
;
import
android.app.NotificationChannel
;
import
android.app.NotificationManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
...
...
@@ -23,6 +25,7 @@ import com.google.firebase.messaging.RemoteMessage;
import
com.google.firebase.messaging.RemoteMessage.Notification
;
import
android.app.Application
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.v4.app.NotificationManagerCompat
;
import
android.support.v4.content.LocalBroadcastManager
;
...
...
@@ -36,6 +39,8 @@ import java.util.Set;
import
java.util.UUID
;
import
com.google.firebase.FirebaseApp
;
import
static
android
.
content
.
Context
.
NOTIFICATION_SERVICE
;
public
class
FIRMessagingModule
extends
ReactContextBaseJavaModule
implements
LifecycleEventListener
,
ActivityEventListener
{
private
final
static
String
TAG
=
FIRMessagingModule
.
class
.
getCanonicalName
();
private
FIRLocalMessagingHelper
mFIRLocalMessagingHelper
;
...
...
@@ -76,6 +81,48 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
@ReactMethod
public
void
createNotificationChannel
(
ReadableMap
details
,
Promise
promise
){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
NotificationManager
mngr
=
(
NotificationManager
)
getReactApplicationContext
().
getSystemService
(
NOTIFICATION_SERVICE
);
String
id
=
details
.
getString
(
"id"
);
String
name
=
details
.
getString
(
"name"
);
String
priority
=
details
.
getString
(
"priority"
);
int
importance
;
switch
(
priority
)
{
case
"min"
:
importance
=
NotificationManager
.
IMPORTANCE_MIN
;
break
;
case
"low"
:
importance
=
NotificationManager
.
IMPORTANCE_LOW
;
break
;
case
"high"
:
importance
=
NotificationManager
.
IMPORTANCE_HIGH
;
break
;
case
"max"
:
importance
=
NotificationManager
.
IMPORTANCE_MAX
;
break
;
default
:
importance
=
NotificationManager
.
IMPORTANCE_DEFAULT
;
}
if
(
mngr
.
getNotificationChannel
(
id
)
!=
null
)
{
promise
.
resolve
(
null
);
return
;
}
//
NotificationChannel
channel
=
new
NotificationChannel
(
id
,
name
,
importance
);
// Configure the notification channel.
if
(
details
.
hasKey
(
"description"
)){
channel
.
setDescription
(
details
.
getString
(
"description"
));
}
mngr
.
createNotificationChannel
(
channel
);
}
promise
.
resolve
(
null
);
}
@ReactMethod
public
void
getFCMToken
(
Promise
promise
)
{
try
{
...
...
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
View file @
cb2c6ccf
...
...
@@ -78,7 +78,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
String
subText
=
bundle
.
getString
(
"sub_text"
);
if
(
subText
!=
null
)
subText
=
URLDecoder
.
decode
(
subText
,
"UTF-8"
);
NotificationCompat
.
Builder
notification
=
new
NotificationCompat
.
Builder
(
mContext
)
NotificationCompat
.
Builder
notification
=
new
NotificationCompat
.
Builder
(
mContext
,
bundle
.
getString
(
"channel"
)
)
.
setContentTitle
(
title
)
.
setContentText
(
body
)
.
setTicker
(
ticker
)
...
...
index.js
View file @
cb2c6ccf
...
...
@@ -90,6 +90,12 @@ FCM.requestPermissions = () => {
return
RNFIRMessaging
.
requestPermissions
();
};
FCM
.
createNotificationChannel
=
(
channel
)
=>
{
if
(
Platform
.
OS
===
'
android
'
)
{
return
RNFIRMessaging
.
createNotificationChannel
(
channel
);
}
}
FCM
.
presentLocalNotification
=
(
details
)
=>
{
details
.
id
=
details
.
id
||
new
Date
().
getTime
().
toString
();
details
.
local_notification
=
true
;
...
...
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