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
45077bc7
Commit
45077bc7
authored
Mar 06, 2018
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert android actions to json objects
parent
aaf3c5e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
6 deletions
+134
-6
android/src/main/java/com/evollu/react/fcm/ReactNativeJson.java
...d/src/main/java/com/evollu/react/fcm/ReactNativeJson.java
+122
-0
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
.../main/java/com/evollu/react/fcm/SendNotificationTask.java
+12
-6
No files found.
android/src/main/java/com/evollu/react/fcm/ReactNativeJson.java
0 → 100644
View file @
45077bc7
package
com.evollu.react.fcm
;
import
com.facebook.react.bridge.ReadableArray
;
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.bridge.WritableNativeArray
;
import
com.facebook.react.bridge.WritableNativeMap
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.Iterator
;
public
class
ReactNativeJson
{
public
static
WritableMap
convertJsonToMap
(
JSONObject
jsonObject
)
throws
JSONException
{
WritableMap
map
=
new
WritableNativeMap
();
Iterator
<
String
>
iterator
=
jsonObject
.
keys
();
while
(
iterator
.
hasNext
())
{
String
key
=
iterator
.
next
();
Object
value
=
jsonObject
.
get
(
key
);
if
(
value
instanceof
JSONObject
)
{
map
.
putMap
(
key
,
convertJsonToMap
((
JSONObject
)
value
));
}
else
if
(
value
instanceof
JSONArray
)
{
map
.
putArray
(
key
,
convertJsonToArray
((
JSONArray
)
value
));
}
else
if
(
value
instanceof
Boolean
)
{
map
.
putBoolean
(
key
,
(
Boolean
)
value
);
}
else
if
(
value
instanceof
Integer
)
{
map
.
putInt
(
key
,
(
Integer
)
value
);
}
else
if
(
value
instanceof
Double
)
{
map
.
putDouble
(
key
,
(
Double
)
value
);
}
else
if
(
value
instanceof
String
)
{
map
.
putString
(
key
,
(
String
)
value
);
}
else
{
map
.
putString
(
key
,
value
.
toString
());
}
}
return
map
;
}
public
static
WritableArray
convertJsonToArray
(
JSONArray
jsonArray
)
throws
JSONException
{
WritableArray
array
=
new
WritableNativeArray
();
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
Object
value
=
jsonArray
.
get
(
i
);
if
(
value
instanceof
JSONObject
)
{
array
.
pushMap
(
convertJsonToMap
((
JSONObject
)
value
));
}
else
if
(
value
instanceof
JSONArray
)
{
array
.
pushArray
(
convertJsonToArray
((
JSONArray
)
value
));
}
else
if
(
value
instanceof
Boolean
)
{
array
.
pushBoolean
((
Boolean
)
value
);
}
else
if
(
value
instanceof
Integer
)
{
array
.
pushInt
((
Integer
)
value
);
}
else
if
(
value
instanceof
Double
)
{
array
.
pushDouble
((
Double
)
value
);
}
else
if
(
value
instanceof
String
)
{
array
.
pushString
((
String
)
value
);
}
else
{
array
.
pushString
(
value
.
toString
());
}
}
return
array
;
}
public
static
JSONObject
convertMapToJson
(
ReadableMap
readableMap
)
throws
JSONException
{
JSONObject
object
=
new
JSONObject
();
ReadableMapKeySetIterator
iterator
=
readableMap
.
keySetIterator
();
while
(
iterator
.
hasNextKey
())
{
String
key
=
iterator
.
nextKey
();
switch
(
readableMap
.
getType
(
key
))
{
case
Null:
object
.
put
(
key
,
JSONObject
.
NULL
);
break
;
case
Boolean:
object
.
put
(
key
,
readableMap
.
getBoolean
(
key
));
break
;
case
Number:
object
.
put
(
key
,
readableMap
.
getDouble
(
key
));
break
;
case
String:
object
.
put
(
key
,
readableMap
.
getString
(
key
));
break
;
case
Map:
object
.
put
(
key
,
convertMapToJson
(
readableMap
.
getMap
(
key
)));
break
;
case
Array:
object
.
put
(
key
,
convertArrayToJson
(
readableMap
.
getArray
(
key
)));
break
;
}
}
return
object
;
}
public
static
JSONArray
convertArrayToJson
(
ReadableArray
readableArray
)
throws
JSONException
{
JSONArray
array
=
new
JSONArray
();
for
(
int
i
=
0
;
i
<
readableArray
.
size
();
i
++)
{
switch
(
readableArray
.
getType
(
i
))
{
case
Null:
break
;
case
Boolean:
array
.
put
(
readableArray
.
getBoolean
(
i
));
break
;
case
Number:
array
.
put
(
readableArray
.
getDouble
(
i
));
break
;
case
String:
array
.
put
(
readableArray
.
getString
(
i
));
break
;
case
Map:
array
.
put
(
convertMapToJson
(
readableArray
.
getMap
(
i
)));
break
;
case
Array:
array
.
put
(
convertArrayToJson
(
readableArray
.
getArray
(
i
)));
break
;
}
}
return
array
;
}
}
android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java
View file @
45077bc7
...
@@ -21,6 +21,11 @@ import android.support.v4.app.NotificationManagerCompat;
...
@@ -21,6 +21,11 @@ import android.support.v4.app.NotificationManagerCompat;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.util.Log
;
import
android.util.Log
;
import
com.facebook.react.bridge.ReadableMap
;
import
com.facebook.react.bridge.WritableArray
;
import
org.json.JSONArray
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
...
@@ -213,20 +218,21 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
...
@@ -213,20 +218,21 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
notification
.
setContentIntent
(
pendingIntent
);
notification
.
setContentIntent
(
pendingIntent
);
if
(
bundle
.
containsKey
(
"android_actions"
))
{
if
(
bundle
.
containsKey
(
"android_actions"
))
{
List
<
String
>
actions
=
bundle
.
getStringArrayList
(
"android_actions"
);
WritableArray
actions
=
ReactNativeJson
.
convertJsonToArray
(
new
JSONArray
(
bundle
.
getString
(
"android_actions"
)));
bundle
.
remove
(
"android_actions"
);
for
(
int
a
=
0
;
a
<
actions
.
size
();
a
++)
{
for
(
int
a
=
0
;
a
<
actions
.
size
();
a
++)
{
String
actionValue
=
actions
.
get
(
a
).
trim
();
ReadableMap
action
=
actions
.
getMap
(
a
);
String
actionTitle
=
action
.
getString
(
"title"
);
String
actionId
=
action
.
getString
(
"id"
);
Intent
actionIntent
=
new
Intent
();
Intent
actionIntent
=
new
Intent
();
actionIntent
.
setClassName
(
mContext
,
intentClassName
);
actionIntent
.
setClassName
(
mContext
,
intentClassName
);
actionIntent
.
setAction
(
"com.evollu.react.fcm."
+
action
Value
+
"_ACTION"
);
actionIntent
.
setAction
(
"com.evollu.react.fcm."
+
action
Id
+
"_ACTION"
);
actionIntent
.
putExtras
(
bundle
);
actionIntent
.
putExtras
(
bundle
);
actionIntent
.
putExtra
(
"_actionIdentifier"
,
action
Value
);
actionIntent
.
putExtra
(
"_actionIdentifier"
,
action
Id
);
actionIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
actionIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
PendingIntent
pendingActionIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
actionIntent
,
PendingIntent
pendingActionIntent
=
PendingIntent
.
getActivity
(
mContext
,
notificationID
,
actionIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
PendingIntent
.
FLAG_UPDATE_CURRENT
);
notification
.
addAction
(
1
,
action
Valu
e
,
pendingActionIntent
);
notification
.
addAction
(
1
,
action
Titl
e
,
pendingActionIntent
);
}
}
}
}
...
...
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