Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
89466fdf
Commit
89466fdf
authored
Oct 20, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update setting for android O
parent
da3d16cd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
7 deletions
+81
-7
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+24
-1
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+56
-5
GCMIntentService.java
...n/java/chat/rocket/android/push/gcm/GCMIntentService.java
+1
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
89466fdf
...
...
@@ -5,6 +5,7 @@
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<permission
android:name=
"chat.rocket.android.permission.C2D_MESSAGE"
...
...
@@ -56,10 +57,32 @@
android:permission=
"com.google.android.c2dm.permission.SEND"
>
<intent-filter>
<action
android:name=
"com.google.android.c2dm.intent.RECEIVE"
/>
<category
android:name=
"com.example.gcm"
/>
<action
android:name=
"com.google.android.c2dm.intent.REGISTRATION"
/>
<category
android:name=
"chat.rocket.android"
/>
</intent-filter>
</receiver>
<receiver
android:name=
"com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported=
"true"
android:permission=
"com.google.android.c2dm.permission.SEND"
>
<intent-filter>
<action
android:name=
"com.google.android.c2dm.intent.RECEIVE"
/>
<category
android:name=
"chat.rocket.android"
/>
</intent-filter>
</receiver>
<receiver
android:name=
"com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported=
"false"
/>
<service
android:name=
"com.google.firebase.iid.FirebaseInstanceIdService"
android:exported=
"true"
>
<intent-filter
android:priority=
"-500"
>
<action
android:name=
"com.google.firebase.INSTANCE_ID_EVENT"
/>
</intent-filter>
</service>
<service
android:name=
".push.gcm.GCMIntentService"
android:exported=
"false"
>
...
...
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
89466fdf
...
...
@@ -92,13 +92,13 @@ object PushManager {
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
notId
=
pushMessage
.
notificationId
.
toInt
()
val
groupNotification
=
createGroupNotification
(
context
,
pushMessage
)
val
groupTuple
=
groupMap
[
pushMessage
.
host
]
val
notification
:
Notification
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
notification
=
createNotificationForOreoAndAbove
(
context
,
pushMessage
)
groupTuple
?.
let
{
val
groupNotification
=
createOreoGroupNotification
(
context
,
pushMessage
)
notificationManager
.
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
}
...
...
@@ -106,6 +106,7 @@ object PushManager {
}
else
{
notification
=
createCompatNotification
(
context
,
pushMessage
)
groupTuple
?.
let
{
val
groupNotification
=
createCompatGroupNotification
(
context
,
pushMessage
)
NotificationManagerCompat
.
from
(
context
).
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
}
...
...
@@ -122,7 +123,7 @@ object PushManager {
}
}
private
fun
createGroupNotification
(
context
:
Context
,
pushMessage
:
PushMessage
):
Notification
{
private
fun
create
Compat
GroupNotification
(
context
:
Context
,
pushMessage
:
PushMessage
):
Notification
{
// Create notification group.
bundleNotificationsToHost
(
pushMessage
.
host
)
val
id
=
pushMessage
.
notificationId
.
toInt
()
...
...
@@ -165,6 +166,51 @@ object PushManager {
return
notGroupBuilder
.
build
()
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
private
fun
createOreoGroupNotification
(
context
:
Context
,
pushMessage
:
PushMessage
):
Notification
{
// Create notification group.
bundleNotificationsToHost
(
pushMessage
.
host
)
val
id
=
pushMessage
.
notificationId
.
toInt
()
val
contentIntent
=
getContentIntent
(
context
,
id
,
pushMessage
,
group
=
true
)
val
deleteIntent
=
getDismissIntent
(
context
,
id
)
val
notGroupBuilder
=
Notification
.
Builder
(
context
,
pushMessage
.
notificationId
)
.
setWhen
(
pushMessage
.
createdAt
)
.
setChannelId
(
pushMessage
.
notificationId
)
.
setContentTitle
(
pushMessage
.
title
.
fromHtml
())
.
setContentText
(
pushMessage
.
message
.
fromHtml
())
.
setGroup
(
pushMessage
.
host
)
.
setGroupSummary
(
true
)
.
setStyle
(
Notification
.
BigTextStyle
().
bigText
(
pushMessage
.
message
.
fromHtml
()))
.
setContentIntent
(
contentIntent
)
.
setDeleteIntent
(
deleteIntent
)
.
setMessageNotification
(
context
)
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
pushMessage
.
host
)
if
(
subText
.
isNotEmpty
())
{
notGroupBuilder
.
setSubText
(
subText
)
}
val
messages
=
messageStack
.
get
(
pushMessage
.
notificationId
.
toInt
())
val
messageCount
=
messages
.
size
if
(
messageCount
>
1
)
{
val
summary
=
pushMessage
.
summaryText
.
replace
(
"%n%"
,
messageCount
.
toString
())
val
inbox
=
Notification
.
InboxStyle
()
.
setBigContentTitle
(
pushMessage
.
title
.
fromHtml
())
.
setSummaryText
(
summary
)
notGroupBuilder
.
setStyle
(
inbox
)
}
else
{
val
bigText
=
Notification
.
BigTextStyle
()
.
bigText
(
pushMessage
.
message
.
fromHtml
())
.
setBigContentTitle
(
pushMessage
.
title
.
fromHtml
())
notGroupBuilder
.
setStyle
(
bigText
)
}
return
notGroupBuilder
.
build
()
}
private
fun
createCompatNotification
(
context
:
Context
,
pushMessage
:
PushMessage
):
Notification
{
with
(
pushMessage
)
{
val
id
=
notificationId
.
toInt
()
...
...
@@ -219,7 +265,7 @@ object PushManager {
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
private
fun
createNotificationForOreoAndAbove
(
context
:
Context
,
pushMessage
:
PushMessage
):
Notification
{
val
notificationM
anager
:
NotificationManager
=
val
m
anager
:
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
with
(
pushMessage
)
{
...
...
@@ -228,8 +274,14 @@ object PushManager {
val
deleteIntent
=
getDismissIntent
(
context
,
id
)
val
channel
=
NotificationChannel
(
notificationId
,
sender
.
username
,
NotificationManager
.
IMPORTANCE_HIGH
)
val
notificationBuilder
=
Notification
.
Builder
(
context
,
pushMessage
.
rid
)
channel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
channel
.
enableLights
(
true
)
channel
.
enableVibration
(
true
)
channel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
channel
)
val
notificationBuilder
=
Notification
.
Builder
(
context
,
notificationId
)
.
setWhen
(
createdAt
)
.
setChannelId
(
notificationId
)
.
setContentTitle
(
title
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setNumber
(
count
.
toInt
())
...
...
@@ -246,7 +298,6 @@ object PushManager {
channel
.
enableLights
(
true
)
channel
.
enableVibration
(
true
)
notificationManager
.
createNotificationChannel
(
channel
)
if
(
"inbox"
==
style
)
{
val
messages
=
messageStack
.
get
(
notificationId
.
toInt
())
...
...
app/src/main/java/chat/rocket/android/push/gcm/GCMIntentService.java
View file @
89466fdf
...
...
@@ -36,7 +36,7 @@ public class GCMIntentService extends GcmListenerService implements PushConstant
PushNotificationHandler
pushNotificationHandler
=
new
PushNotificationHandler
();
//
pushNotificationHandler.showNotificationIfPossible(applicationContext, extras);
pushNotificationHandler
.
showNotificationIfPossible
(
applicationContext
,
extras
);
PushManager
.
INSTANCE
.
handle
(
applicationContext
,
extras
);
}
...
...
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