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
d01821f5
Commit
d01821f5
authored
Mar 21, 2018
by
Libin Lu
Committed by
GitHub
Mar 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #842 from ksegla/patch-1
Decode utf-8 before presentation
parents
24e8fe70
b3be22e2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
13 deletions
+37
-13
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
.../main/java/com/evollu/react/fcm/SendNotificationTask.java
+37
-13
No files found.
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
View file @
d01821f5
...
@@ -30,6 +30,7 @@ import java.io.IOException;
...
@@ -30,6 +30,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
static
com
.
facebook
.
react
.
common
.
ReactConstants
.
TAG
;
import
static
com
.
facebook
.
react
.
common
.
ReactConstants
.
TAG
;
...
@@ -55,9 +56,11 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -55,9 +56,11 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
return
null
;
return
null
;
}
}
if
(
bundle
.
getString
(
"body"
)
==
null
)
{
String
body
=
bundle
.
getString
(
"body"
);
if
(
body
==
null
)
{
return
null
;
return
null
;
}
}
body
=
URLDecoder
.
decode
(
body
,
"UTF-8"
);
Resources
res
=
mContext
.
getResources
();
Resources
res
=
mContext
.
getResources
();
String
packageName
=
mContext
.
getPackageName
();
String
packageName
=
mContext
.
getPackageName
();
...
@@ -67,20 +70,29 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -67,20 +70,29 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
ApplicationInfo
appInfo
=
mContext
.
getApplicationInfo
();
ApplicationInfo
appInfo
=
mContext
.
getApplicationInfo
();
title
=
mContext
.
getPackageManager
().
getApplicationLabel
(
appInfo
).
toString
();
title
=
mContext
.
getPackageManager
().
getApplicationLabel
(
appInfo
).
toString
();
}
}
title
=
URLDecoder
.
decode
(
title
,
"UTF-8"
);
String
ticker
=
bundle
.
getString
(
"ticker"
);
if
(
ticker
!=
null
)
ticker
=
URLDecoder
.
decode
(
ticker
,
"UTF-8"
);
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
)
.
setContentTitle
(
title
)
.
setContentTitle
(
title
)
.
setContentText
(
b
undle
.
getString
(
"body"
)
)
.
setContentText
(
b
ody
)
.
setTicker
(
bundle
.
getString
(
"ticker"
)
)
.
setTicker
(
ticker
)
.
setVisibility
(
NotificationCompat
.
VISIBILITY_PRIVATE
)
.
setVisibility
(
NotificationCompat
.
VISIBILITY_PRIVATE
)
.
setAutoCancel
(
bundle
.
getBoolean
(
"auto_cancel"
,
true
))
.
setAutoCancel
(
bundle
.
getBoolean
(
"auto_cancel"
,
true
))
.
setNumber
((
int
)
bundle
.
getDouble
(
"number"
))
.
setNumber
((
int
)
bundle
.
getDouble
(
"number"
))
.
setSubText
(
bundle
.
getString
(
"sub_text"
)
)
.
setSubText
(
subText
)
.
setVibrate
(
new
long
[]{
0
,
DEFAULT_VIBRATION
})
.
setVibrate
(
new
long
[]{
0
,
DEFAULT_VIBRATION
})
.
setExtras
(
bundle
.
getBundle
(
"data"
));
.
setExtras
(
bundle
.
getBundle
(
"data"
));
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
){
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
){
notification
.
setGroup
(
bundle
.
getString
(
"group"
));
String
group
=
bundle
.
getString
(
"group"
);
if
(
group
!=
null
)
group
=
URLDecoder
.
decode
(
group
,
"UTF-8"
);
notification
.
setGroup
(
group
);
}
}
if
(
bundle
.
containsKey
(
"ongoing"
)
&&
bundle
.
getBoolean
(
"ongoing"
))
{
if
(
bundle
.
containsKey
(
"ongoing"
)
&&
bundle
.
getBoolean
(
"ongoing"
))
{
...
@@ -116,6 +128,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -116,6 +128,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
//large icon
//large icon
String
largeIcon
=
bundle
.
getString
(
"large_icon"
);
String
largeIcon
=
bundle
.
getString
(
"large_icon"
);
if
(
largeIcon
!=
null
&&
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
LOLLIPOP
){
if
(
largeIcon
!=
null
&&
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
LOLLIPOP
){
largeIcon
=
URLDecoder
.
decode
(
largeIcon
,
"UTF-8"
);
if
(
largeIcon
.
startsWith
(
"http://"
)
||
largeIcon
.
startsWith
(
"https://"
))
{
if
(
largeIcon
.
startsWith
(
"http://"
)
||
largeIcon
.
startsWith
(
"https://"
))
{
Bitmap
bitmap
=
getBitmapFromURL
(
largeIcon
);
Bitmap
bitmap
=
getBitmapFromURL
(
largeIcon
);
notification
.
setLargeIcon
(
bitmap
);
notification
.
setLargeIcon
(
bitmap
);
...
@@ -132,12 +145,15 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -132,12 +145,15 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
//big text
//big text
String
bigText
=
bundle
.
getString
(
"big_text"
);
String
bigText
=
bundle
.
getString
(
"big_text"
);
if
(
bigText
!=
null
){
if
(
bigText
!=
null
){
bigText
=
URLDecoder
.
decode
(
bigText
,
"UTF-8"
);
notification
.
setStyle
(
new
NotificationCompat
.
BigTextStyle
().
bigText
(
bigText
));
notification
.
setStyle
(
new
NotificationCompat
.
BigTextStyle
().
bigText
(
bigText
));
}
}
//picture
//picture
String
picture
=
bundle
.
getString
(
"picture"
);
String
picture
=
bundle
.
getString
(
"picture"
);
if
(
picture
!=
null
){
if
(
picture
!=
null
){
picture
=
URLDecoder
.
decode
(
picture
,
"UTF-8"
);
NotificationCompat
.
BigPictureStyle
bigPicture
=
new
NotificationCompat
.
BigPictureStyle
();
NotificationCompat
.
BigPictureStyle
bigPicture
=
new
NotificationCompat
.
BigPictureStyle
();
if
(
picture
.
startsWith
(
"http://"
)
||
picture
.
startsWith
(
"https://"
))
{
if
(
picture
.
startsWith
(
"http://"
)
||
picture
.
startsWith
(
"https://"
))
{
...
@@ -152,7 +168,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -152,7 +168,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
}
}
}
}
bigPicture
.
setBigContentTitle
(
title
);
bigPicture
.
setBigContentTitle
(
title
);
bigPicture
.
setSummaryText
(
b
undle
.
getString
(
"body"
)
);
bigPicture
.
setSummaryText
(
b
ody
);
notification
.
setStyle
(
bigPicture
);
notification
.
setStyle
(
bigPicture
);
}
}
...
@@ -160,6 +176,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -160,6 +176,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
//sound
//sound
String
soundName
=
bundle
.
getString
(
"sound"
);
String
soundName
=
bundle
.
getString
(
"sound"
);
if
(
soundName
!=
null
)
{
if
(
soundName
!=
null
)
{
soundName
=
URLDecoder
.
decode
(
soundName
,
"UTF-8"
);
if
(
soundName
.
equalsIgnoreCase
(
"default"
))
{
if
(
soundName
.
equalsIgnoreCase
(
"default"
))
{
notification
.
setSound
(
RingtoneManager
.
getDefaultUri
(
RingtoneManager
.
TYPE_NOTIFICATION
));
notification
.
setSound
(
RingtoneManager
.
getDefaultUri
(
RingtoneManager
.
TYPE_NOTIFICATION
));
}
else
{
}
else
{
...
@@ -178,6 +195,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -178,6 +195,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
String
color
=
bundle
.
getString
(
"color"
);
String
color
=
bundle
.
getString
(
"color"
);
if
(
color
!=
null
)
{
if
(
color
!=
null
)
{
color
=
URLDecoder
.
decode
(
color
,
"UTF-8"
);
notification
.
setColor
(
Color
.
parseColor
(
color
));
notification
.
setColor
(
Color
.
parseColor
(
color
));
}
}
}
}
...
@@ -209,7 +227,11 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -209,7 +227,11 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
intent
.
setClassName
(
mContext
,
intentClassName
);
intent
.
setClassName
(
mContext
,
intentClassName
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
intent
.
putExtras
(
bundle
);
intent
.
putExtras
(
bundle
);
intent
.
setAction
(
bundle
.
getString
(
"click_action"
));
String
clickAction
=
bundle
.
getString
(
"click_action"
);
if
(
clickAction
!=
null
)
clickAction
=
URLDecoder
.
decode
(
clickAction
,
"UTF-8"
);
intent
.
setAction
(
clickAction
);
int
notificationID
=
bundle
.
containsKey
(
"id"
)
?
bundle
.
getString
(
"id"
,
""
).
hashCode
()
:
(
int
)
System
.
currentTimeMillis
();
int
notificationID
=
bundle
.
containsKey
(
"id"
)
?
bundle
.
getString
(
"id"
,
""
).
hashCode
()
:
(
int
)
System
.
currentTimeMillis
();
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
intent
,
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
intent
,
...
@@ -218,7 +240,10 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -218,7 +240,10 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
notification
.
setContentIntent
(
pendingIntent
);
notification
.
setContentIntent
(
pendingIntent
);
if
(
bundle
.
containsKey
(
"android_actions"
))
{
if
(
bundle
.
containsKey
(
"android_actions"
))
{
WritableArray
actions
=
ReactNativeJson
.
convertJsonToArray
(
new
JSONArray
(
bundle
.
getString
(
"android_actions"
)));
String
androidActions
=
bundle
.
getString
(
"android_actions"
);
androidActions
=
URLDecoder
.
decode
(
androidActions
,
"UTF-8"
);
WritableArray
actions
=
ReactNativeJson
.
convertJsonToArray
(
new
JSONArray
(
androidActions
));
for
(
int
a
=
0
;
a
<
actions
.
size
();
a
++)
{
for
(
int
a
=
0
;
a
<
actions
.
size
();
a
++)
{
ReadableMap
action
=
actions
.
getMap
(
a
);
ReadableMap
action
=
actions
.
getMap
(
a
);
String
actionTitle
=
action
.
getString
(
"title"
);
String
actionTitle
=
action
.
getString
(
"title"
);
...
@@ -282,4 +307,3 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -282,4 +307,3 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
return
launchIntent
!=
null
?
launchIntent
.
getComponent
().
getClassName
()
:
null
;
return
launchIntent
!=
null
?
launchIntent
.
getComponent
().
getClassName
()
:
null
;
}
}
}
}
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