use of android.app.NotificationChannel in project ForPDA by RadiationX.
the class SimpleUpdateChecker method checkUpdate.
private void checkUpdate(JSONObject updateObject, Context context, String jsonSource) throws JSONException {
if (context == null) {
context = App.getContext();
}
final int currentVersionCode = BuildConfig.VERSION_CODE;
final int versionCode = Integer.parseInt(updateObject.getString("version_code"));
if (versionCode > currentVersionCode) {
final String versionName = updateObject.getString("version_name");
String channelId = "forpda_channel_updates";
String channelName = context.getString(R.string.updater_notification_title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = context.getSystemService(NotificationManager.class);
if (manager != null) {
manager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId);
NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
mBuilder.setSmallIcon(R.drawable.ic_notify_mention);
mBuilder.setContentTitle(context.getString(R.string.updater_notification_title));
mBuilder.setContentText(String.format(context.getString(R.string.updater_notification_content_VerName), versionName));
mBuilder.setChannelId(channelId);
Intent notifyIntent = new Intent(context, UpdateCheckerActivity.class);
// notifyIntent.setData(Uri.parse(createIntentUrl(notificationEvent)));
notifyIntent.putExtra(UpdateCheckerActivity.JSON_SOURCE, jsonSource);
notifyIntent.setAction(Intent.ACTION_VIEW);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);
mBuilder.setContentIntent(notifyPendingIntent);
mBuilder.setAutoCancel(true);
mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
mBuilder.setCategory(NotificationCompat.CATEGORY_EVENT);
int defaults = 0;
/*if (Preferences.Notifications.Main.isSoundEnabled()) {
defaults |= NotificationCompat.DEFAULT_SOUND;
}*/
if (Preferences.Notifications.Main.isVibrationEnabled(null)) {
defaults |= NotificationCompat.DEFAULT_VIBRATE;
}
mBuilder.setDefaults(defaults);
mNotificationManager.notify(versionCode, mBuilder.build());
}
}
use of android.app.NotificationChannel in project ForPDA by RadiationX.
the class NotificationsService method sendNotifications.
public void sendNotifications(List<NotificationEvent> events, NotificationEvent.Source tSource) {
if (events.isEmpty()) {
return;
}
if (events.size() <= STACKED_MAX) {
for (NotificationEvent event : events) {
sendNotification(event);
}
return;
}
if (!checkNotify(null, tSource)) {
return;
}
String title = createStackedTitle(events);
CharSequence text = createStackedContent(events);
String summaryText = createStackedSummary(events);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(text);
bigTextStyle.setSummaryText(summaryText);
String channelId = getChannelId(events.get(0));
String channelName = getChannelName(events.get(0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
NotificationCompat.Builder builder;
builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(createStackedSmallIcon(events));
builder.setContentTitle(title);
builder.setContentText(text);
builder.setStyle(bigTextStyle);
builder.setChannelId(channelId);
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setData(Uri.parse(createStackedIntentUrl(events)));
notifyIntent.setAction(Intent.ACTION_VIEW);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
builder.setContentIntent(notifyPendingIntent);
configureNotification(builder);
int id = 0;
NotificationEvent event = events.get(0);
if (event.fromQms()) {
id = NOTIFY_STACKED_QMS_ID;
} else if (event.fromTheme()) {
id = NOTIFY_STACKED_FAV_ID;
}
mNotificationManager.notify(id, builder.build());
}
use of android.app.NotificationChannel in project hello-storj by kaloyan-raev.
the class FileTransferChannel method create.
public static void create(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// The user-visible name of the channel.
CharSequence name = context.getString(R.string.channel_name);
// The user-visible description of the channel.
String description = context.getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new android.app.NotificationChannel(ID, name, importance);
// Configure the notification channel.
channel.setDescription(description);
channel.enableLights(false);
channel.enableVibration(false);
notificationManager.createNotificationChannel(channel);
}
}
use of android.app.NotificationChannel in project android_packages_apps_Updater by LineageOS.
the class UpdatesCheckReceiver method showNotification.
private static void showNotification(Context context) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = new NotificationChannel(NEW_UPDATES_NOTIFICATION_CHANNEL, context.getString(R.string.new_updates_channel_title), NotificationManager.IMPORTANCE_LOW);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NEW_UPDATES_NOTIFICATION_CHANNEL);
notificationBuilder.setSmallIcon(R.drawable.ic_system_update);
Intent notificationIntent = new Intent(context, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(intent);
notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title));
notificationBuilder.setAutoCancel(true);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(0, notificationBuilder.build());
}
use of android.app.NotificationChannel in project toshi-android-client by toshiapp.
the class ToshiNotificationBuilder method createPaymentsChannel.
@RequiresApi(api = 26)
private static NotificationChannel createPaymentsChannel() {
final String id = String.valueOf(SofaType.PAYMENT);
final NotificationChannel notificationChannel = new NotificationChannel(id, PAYMENTS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
return addNotificationAttributes(notificationChannel);
}
Aggregations