use of android.app.NotificationChannel in project run-wallet-android by runplay.
the class NotificationHelper method createNotificationChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, context.getResources().getString(R.string.app_name), NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
}
use of android.app.NotificationChannel in project xabber-android by redsolution.
the class NotificationManager method createNotificationChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
public String createNotificationChannel() {
String channelId = "xabber_notification";
String channelName = "Xabber Notification";
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(channelId, channelName, android.app.NotificationManager.IMPORTANCE_HIGH);
android.app.NotificationManager service = (android.app.NotificationManager) Application.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
if (service != null)
service.createNotificationChannel(channel);
return channelId;
}
use of android.app.NotificationChannel in project mobile-center-sdk-android by Microsoft.
the class PushNotifier method handleNotification.
/**
* Builds a push notification using the given context and intent.
*
* @param context The current context.
* @param pushIntent The intent that is associated with the push.
*/
static void handleNotification(Context context, Intent pushIntent) throws RuntimeException {
context = context.getApplicationContext();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
/* Generate notification identifier using the hash of the Google message id. */
String messageId = PushIntentUtils.getGoogleMessageId(pushIntent);
if (messageId == null) {
AppCenterLog.error(LOG_TAG, "Push notification did not" + "contain Google message ID; aborting notification processing.");
return;
}
int notificationId = messageId.hashCode();
/* Click action. */
PackageManager packageManager = context.getPackageManager();
Intent actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName());
if (actionIntent != null) {
actionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Map<String, String> customData = PushIntentUtils.getCustomData(pushIntent);
for (String key : customData.keySet()) {
actionIntent.putExtra(key, customData.get(key));
}
/* Set the message ID in the intent. */
PushIntentUtils.setGoogleMessageId(messageId, actionIntent);
} else {
/* If no launcher, just create a placeholder action as the field is mandatory. */
actionIntent = new Intent();
}
/* Get text. Use app name for title if title is missing. */
String notificationTitle = PushIntentUtils.getTitle(pushIntent);
if (notificationTitle == null || notificationTitle.isEmpty()) {
notificationTitle = AppNameHelper.getAppName(context);
}
String notificationMessage = PushIntentUtils.getMessage(pushIntent);
/* Start building notification. */
Notification.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
/* Get channel. */
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
/* Create or update channel. */
// noinspection ConstantConditions
notificationManager.createNotificationChannel(channel);
/* And associate to notification. */
builder = new Notification.Builder(context, channel.getId());
} else {
builder = getOldNotificationBuilder(context);
}
/* Set color. */
setColor(pushIntent, builder);
/* Set icon. */
setIcon(context, pushIntent, builder);
/* Set sound. */
setSound(context, pushIntent, builder);
/* Texts */
builder.setContentTitle(notificationTitle).setContentText(notificationMessage).setWhen(System.currentTimeMillis());
/* Click action. Reuse notification id for simplicity. */
PendingIntent contentIntent = PendingIntent.getActivity(context, notificationId, actionIntent, 0);
builder.setContentIntent(contentIntent);
/* Build method depends on versions. */
Notification notification;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notification = builder.build();
} else {
notification = getOldNotification(builder);
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// noinspection ConstantConditions
notificationManager.notify(notificationId, notification);
}
use of android.app.NotificationChannel in project android-UniversalMusicPlayer by googlesamples.
the class MediaNotificationManager method createNotificationChannel.
/**
* Creates Notification Channel. This is required in Android O+ to display notifications.
*/
@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
if (mNotificationManager.getNotificationChannel(CHANNEL_ID) == null) {
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, mService.getString(R.string.notification_channel), NotificationManager.IMPORTANCE_LOW);
notificationChannel.setDescription(mService.getString(R.string.notification_channel_description));
mNotificationManager.createNotificationChannel(notificationChannel);
}
}
use of android.app.NotificationChannel in project Talon-for-Twitter by klinker24.
the class App method initChannel.
public void initChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.createNotificationChannel(new NotificationChannel(TALON_SERVICE_CHANNEL_ID, TALON_SERVICE_CHANNEL_DESCRIPTION, NotificationManager.IMPORTANCE_DEFAULT));
}
}
Aggregations