Android N: customized notifications

Closes #453
This commit is contained in:
M66B 2016-07-03 09:54:35 +02:00
parent 84db324612
commit bab4790ef7
1 changed files with 27 additions and 11 deletions

View File

@ -1938,13 +1938,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_security_white_24dp)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_started))
.setContentIntent(pi)
.setColor(tv.data)
.setOngoing(true)
.setAutoCancel(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setContentTitle(getString(R.string.msg_started));
else
builder.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_started));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
@ -1952,13 +1956,21 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
}
if (allowed > 0 || blocked > 0 || hosts > 0) {
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_started));
if (Util.isPlayStoreInstall(this))
notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
else
notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
return notification.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (Util.isPlayStoreInstall(this))
builder.setContentText(getString(R.string.msg_packages, allowed, blocked));
else
builder.setContentText(getString(R.string.msg_hosts, allowed, blocked, hosts));
return builder.build();
} else {
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_started));
if (Util.isPlayStoreInstall(this))
notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
else
notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
return notification.build();
}
} else
return builder.build();
}
@ -1978,13 +1990,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_security_white_24dp)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_waiting))
.setContentIntent(pi)
.setColor(tv.data)
.setOngoing(true)
.setAutoCancel(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setContentTitle(getString(R.string.msg_waiting));
else
builder.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_waiting));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)