Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
90a8b75f
Commit
90a8b75f
authored
Jul 29, 2018
by
Sajal Narang
Committed by
GitHub
Jul 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #159 from pulsejet/on
Fix notifications for Oreo
parents
686a1c48
9726a010
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
16 deletions
+57
-16
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-1
app/src/main/java/app/insti/MainActivity.java
app/src/main/java/app/insti/MainActivity.java
+44
-2
app/src/main/java/app/insti/notifications/NotificationEventReceiver.java
...va/app/insti/notifications/NotificationEventReceiver.java
+3
-3
app/src/main/java/app/insti/notifications/NotificationIntentService.java
...va/app/insti/notifications/NotificationIntentService.java
+8
-10
No files found.
app/src/main/AndroidManifest.xml
View file @
90a8b75f
...
@@ -113,7 +113,8 @@
...
@@ -113,7 +113,8 @@
<service
<service
android:name=
".notifications.NotificationIntentService"
android:name=
".notifications.NotificationIntentService"
android:enabled=
"true"
android:enabled=
"true"
android:exported=
"false"
/>
android:exported=
"false"
android:permission=
"android.permission.BIND_JOB_SERVICE"
/>
<receiver
android:name=
".notifications.NotificationEventReceiver"
/>
<receiver
android:name=
".notifications.NotificationEventReceiver"
/>
<receiver
android:name=
".notifications.NotificationServiceStarterReceiver"
>
<receiver
android:name=
".notifications.NotificationServiceStarterReceiver"
>
...
...
app/src/main/java/app/insti/MainActivity.java
View file @
90a8b75f
package
app.insti
;
package
app.insti
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.NotificationChannel
;
import
android.app.NotificationManager
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.design.widget.NavigationView
;
import
android.support.design.widget.NavigationView
;
...
@@ -70,6 +75,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -70,6 +75,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
initPicasso
();
initPicasso
();
}
catch
(
IllegalStateException
ignored
)
{
}
catch
(
IllegalStateException
ignored
)
{
}
}
/* Make notification channel on oreo */
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
O
)
{
createNotificationChannel
();
}
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
session
=
new
SessionManager
(
getApplicationContext
());
session
=
new
SessionManager
(
getApplicationContext
());
...
@@ -98,8 +109,39 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -98,8 +109,39 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
}
}
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
O
)
NotificationEventReceiver
.
setupAlarm
(
getApplicationContext
());
NotificationEventReceiver
.
setupAlarm
(
getApplicationContext
());
}
@TargetApi
(
Build
.
VERSION_CODES
.
O
)
private
void
createNotificationChannel
()
{
NotificationManager
mNotificationManager
=
(
NotificationManager
)
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
// The id of the channel.
String
id
=
"INSTIAPP_CHANNEL"
;
// The user-visible name of the channel.
CharSequence
name
=
"InstiApp"
;
// The user-visible description of the channel.
String
description
=
"InstiApp Notifications"
;
int
importance
=
NotificationManager
.
IMPORTANCE_HIGH
;
NotificationChannel
mChannel
=
null
;
mChannel
=
new
NotificationChannel
(
id
,
name
,
importance
);
// Configure the notification channel.
mChannel
.
setDescription
(
description
);
mChannel
.
enableLights
(
true
);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel
.
setLightColor
(
Color
.
RED
);
mChannel
.
enableVibration
(
true
);
mChannel
.
setVibrationPattern
(
new
long
[]{
100
,
200
,
300
,
400
,
500
,
400
,
300
,
200
,
400
});
mNotificationManager
.
createNotificationChannel
(
mChannel
);
}
}
private
void
handleIntent
(
Intent
appLinkIntent
)
{
private
void
handleIntent
(
Intent
appLinkIntent
)
{
...
...
app/src/main/java/app/insti/notifications/NotificationEventReceiver.java
View file @
90a8b75f
...
@@ -2,16 +2,16 @@ package app.insti.notifications;
...
@@ -2,16 +2,16 @@ package app.insti.notifications;
import
android.app.AlarmManager
;
import
android.app.AlarmManager
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.support.v4.content.WakefulBroadcastReceiver
;
import
android.util.Log
;
import
android.util.Log
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
public
class
public
class
NotificationEventReceiver
extends
Wakeful
BroadcastReceiver
{
NotificationEventReceiver
extends
BroadcastReceiver
{
private
static
final
String
ACTION_START_NOTIFICATION_SERVICE
=
"ACTION_START_NOTIFICATION_SERVICE"
;
private
static
final
String
ACTION_START_NOTIFICATION_SERVICE
=
"ACTION_START_NOTIFICATION_SERVICE"
;
private
static
final
String
ACTION_DELETE_NOTIFICATION
=
"ACTION_DELETE_NOTIFICATION"
;
private
static
final
String
ACTION_DELETE_NOTIFICATION
=
"ACTION_DELETE_NOTIFICATION"
;
...
@@ -57,7 +57,7 @@ NotificationEventReceiver extends WakefulBroadcastReceiver {
...
@@ -57,7 +57,7 @@ NotificationEventReceiver extends WakefulBroadcastReceiver {
}
}
if
(
serviceIntent
!=
null
)
{
if
(
serviceIntent
!=
null
)
{
startWakefulService
(
context
,
serviceIntent
);
NotificationIntentService
.
enqueueWork
(
context
,
NotificationIntentService
.
class
,
200
,
serviceIntent
);
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/app/insti/notifications/NotificationIntentService.java
View file @
90a8b75f
package
app.insti.notifications
;
package
app.insti.notifications
;
import
android.app.IntentService
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
...
@@ -8,8 +7,8 @@ import android.content.Context;
...
@@ -8,8 +7,8 @@ import android.content.Context;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.BitmapFactory
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.support.v4.app.JobIntentService
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.content.WakefulBroadcastReceiver
;
import
android.util.Log
;
import
android.util.Log
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -28,7 +27,7 @@ import retrofit2.Call;
...
@@ -28,7 +27,7 @@ import retrofit2.Call;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
public
class
NotificationIntentService
extends
IntentService
{
public
class
NotificationIntentService
extends
Job
IntentService
{
private
static
final
String
ACTION_START
=
"ACTION_START"
;
private
static
final
String
ACTION_START
=
"ACTION_START"
;
private
static
final
String
ACTION_DELETE
=
"ACTION_DELETE"
;
private
static
final
String
ACTION_DELETE
=
"ACTION_DELETE"
;
...
@@ -39,7 +38,7 @@ public class NotificationIntentService extends IntentService {
...
@@ -39,7 +38,7 @@ public class NotificationIntentService extends IntentService {
private
NotificationManager
manager
;
private
NotificationManager
manager
;
public
NotificationIntentService
()
{
public
NotificationIntentService
()
{
super
(
NotificationIntentService
.
class
.
getSimpleName
()
);
super
();
}
}
public
static
Intent
createIntentStartNotificationService
(
Context
context
)
{
public
static
Intent
createIntentStartNotificationService
(
Context
context
)
{
...
@@ -60,7 +59,7 @@ public class NotificationIntentService extends IntentService {
...
@@ -60,7 +59,7 @@ public class NotificationIntentService extends IntentService {
}
}
@Override
@Override
protected
void
onHandle
Intent
(
Intent
intent
)
{
protected
void
onHandle
Work
(
Intent
intent
)
{
Log
.
d
(
getClass
().
getSimpleName
(),
"onHandleIntent, started handling a notification event"
);
Log
.
d
(
getClass
().
getSimpleName
(),
"onHandleIntent, started handling a notification event"
);
try
{
try
{
String
action
=
intent
.
getAction
();
String
action
=
intent
.
getAction
();
...
@@ -98,9 +97,7 @@ public class NotificationIntentService extends IntentService {
...
@@ -98,9 +97,7 @@ public class NotificationIntentService extends IntentService {
Intent
mapIntent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
gmmIntentUri
);
Intent
mapIntent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
gmmIntentUri
);
startActivity
(
mapIntent
);
startActivity
(
mapIntent
);
}
}
}
finally
{
}
finally
{
}
WakefulBroadcastReceiver
.
completeWakefulIntent
(
intent
);
}
}
}
private
void
processDeleteNotification
(
Intent
intent
)
{
private
void
processDeleteNotification
(
Intent
intent
)
{
...
@@ -122,9 +119,10 @@ public class NotificationIntentService extends IntentService {
...
@@ -122,9 +119,10 @@ public class NotificationIntentService extends IntentService {
if
(
goingEventList
!=
null
)
{
if
(
goingEventList
!=
null
)
{
for
(
Event
event
:
goingEventList
)
{
for
(
Event
event
:
goingEventList
)
{
long
timediff
=
getDateDiff
(
new
Date
(),
event
.
getEventStartTime
(),
TimeUnit
.
MINUTES
);
long
timediff
=
getDateDiff
(
new
Date
(),
event
.
getEventStartTime
(),
TimeUnit
.
MINUTES
);
if
(
timediff
<=
3
0
&&
timediff
>
0
)
{
// Change this to 30*10000 for testing
if
(
timediff
<=
5
0
&&
timediff
>
0
)
{
// Change this to 30*10000 for testing
NOTIFICATION_ID
=
event
.
getEventID
().
hashCode
();
NOTIFICATION_ID
=
event
.
getEventID
().
hashCode
();
final
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
getApplicationContext
());
final
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
getApplicationContext
(),
"INSTIAPP_CHANNEL"
);
builder
.
setContentTitle
(
event
.
getEventName
())
builder
.
setContentTitle
(
event
.
getEventName
())
.
setAutoCancel
(
true
)
.
setAutoCancel
(
true
)
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorAccent
))
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorAccent
))
...
...
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