forked from kaknazaveshtakipishi/PermissionEverywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix notification appearance in Android O.
- Loading branch information
1 parent
5a859d4
commit c752969
Showing
6 changed files
with
72 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon Dec 28 10:00:20 PST 2015 | ||
#Thu Dec 06 19:44:26 EET 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 52 additions & 38 deletions
90
library/src/main/java/com/permissioneverywhere/NotificationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
package com.permissioneverywhere; | ||
|
||
import android.Manifest; | ||
import android.app.Notification; | ||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.media.RingtoneManager; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.support.v4.app.NotificationCompat; | ||
import android.support.v4.os.ResultReceiver; | ||
|
||
class NotificationHelper { | ||
public static final int REQUEST_CODE_PUSH = 77; | ||
|
||
class NotificationHelper { | ||
public static final int REQUEST_CODE_PUSH = 77; | ||
|
||
public static void sendNotification(Context context, | ||
String[] permissions, | ||
int requestCode, | ||
String notificationTitle, | ||
String notificationText, | ||
int notificationIcon, | ||
ResultReceiver receiver) { | ||
|
||
Intent intent = new Intent(context, PermissionActivity.class); | ||
intent.putExtra(Const.REQUEST_CODE, requestCode); | ||
intent.putExtra(Const.PERMISSIONS_ARRAY, permissions); | ||
intent.putExtra(Const.RESULT_RECEIVER, receiver); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); | ||
|
||
PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_PUSH, intent, | ||
PendingIntent.FLAG_ONE_SHOT); | ||
|
||
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | ||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) | ||
.setSmallIcon(notificationIcon) | ||
.setContentTitle(notificationTitle) | ||
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)) | ||
.setContentText(notificationText) | ||
.setAutoCancel(true) | ||
.setSound(defaultSoundUri) | ||
.setPriority(Notification.PRIORITY_HIGH) | ||
.setVibrate(new long[0]) | ||
.setContentIntent(pendingIntent); | ||
|
||
NotificationManager notificationManager = | ||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
notificationManager.notify(requestCode, notificationBuilder.build()); | ||
} | ||
private static final String CHANNEL_ID = "permission"; | ||
|
||
public static void sendNotification(Context context, | ||
String[] permissions, | ||
int requestCode, | ||
String notificationTitle, | ||
String notificationText, | ||
int notificationIcon, | ||
ResultReceiver receiver) { | ||
|
||
Intent intent = new Intent(context, PermissionActivity.class); | ||
intent.putExtra(Const.REQUEST_CODE, requestCode); | ||
intent.putExtra(Const.PERMISSIONS_ARRAY, permissions); | ||
intent.putExtra(Const.RESULT_RECEIVER, receiver); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); | ||
} | ||
|
||
PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_PUSH, intent, | ||
PendingIntent.FLAG_ONE_SHOT); | ||
|
||
NotificationManager notificationManager = | ||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_name), NotificationManager.IMPORTANCE_HIGH); | ||
notificationChannel.enableLights(true); | ||
notificationChannel.setLightColor(Color.RED); | ||
notificationChannel.setShowBadge(true); | ||
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); | ||
notificationManager.createNotificationChannel(notificationChannel); | ||
} | ||
|
||
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | ||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID) | ||
.setSmallIcon(notificationIcon) | ||
.setContentTitle(notificationTitle) | ||
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)) | ||
.setContentText(notificationText) | ||
.setAutoCancel(true) | ||
.setSound(defaultSoundUri) | ||
.setPriority(NotificationCompat.PRIORITY_HIGH) | ||
.setVibrate(new long[0]) | ||
.setContentIntent(pendingIntent); | ||
|
||
notificationManager.notify(requestCode, notificationBuilder.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<resources> | ||
<string name="app_name">PermissionEverywhere</string> | ||
<string name="channel_name">Permission request</string> | ||
</resources> |