Skip to content

Commit

Permalink
Fix notification appearance in Android O.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Dec 6, 2018
1 parent 5a859d4 commit c752969
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 55 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "com.permissioneverywhere.demo"
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +20,8 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.github.kaknazaveshtakipishi:PermissionEverywhere:alpha'
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.github.kaknazaveshtakipishi:PermissionEverywhere:1.0.2'
}
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -16,6 +17,7 @@ allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
14 changes: 7 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 11
targetSdkVersion 23
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -19,7 +19,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
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());
}
}
1 change: 1 addition & 0 deletions library/src/main/res/values/strings.xml
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>

0 comments on commit c752969

Please sign in to comment.