本文整理汇总了Java中android.app.NotificationManager.createNotificationChannel方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationManager.createNotificationChannel方法的具体用法?Java NotificationManager.createNotificationChannel怎么用?Java NotificationManager.createNotificationChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.NotificationManager
的用法示例。
在下文中一共展示了NotificationManager.createNotificationChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onCreate(){
if(DEBUG) Log.i(TAG,"Service Started");
proximitySensorDetails = new ProximitySensorDetails(this);
IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenStateReceiver, screenStateFilter);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL, "BlueBolt Pocket Mode", NotificationManager.IMPORTANCE_UNSPECIFIED);
notificationManager.createNotificationChannel(notificationChannel);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, SplashActivity.class), 0);
Notification.Builder builder = new Notification.Builder(this, CHANNEL);
builder.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setSmallIcon(R.mipmap.ic_launcher_foreground)
.setContentIntent(pendingIntent)
.setOngoing(true);
if(DEBUG) Log.i(TAG,"Notification Created");
startForeground(1, builder.build());
}
}
示例2: onStartCommand
import android.app.NotificationManager; //导入方法依赖的package包/类
public @StartResult int onStartCommand(Intent intent, @StartArgFlags int flags, int startId) {
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_STATUS,
getString(R.string.notification_category_alive),
NotificationManager.IMPORTANCE_MIN);
manager.createNotificationChannel(channel);
}
Notification notification = new NotificationCompat.Builder(this,
CHANNEL_STATUS)
.setContentTitle(getString(R.string.notification_alive))
.setSmallIcon(R.mipmap.ic_app)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setOngoing(true)
.build();
manager.notify(NOTIFICATION_ALIVE_ID, notification);
startForeground(NOTIFICATION_ALIVE_ID, notification);
return START_STICKY;
}
示例3: showNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void showNotification() {
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, getString(R.string.aequorea_offline_cache), NotificationManager.IMPORTANCE_DEFAULT);
mNotificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID).setSmallIcon(R.mipmap.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.caching_offline_article));
if (mNotificationManager != null) {
mNotificationManager.notify(1, builder.build());
}
}
示例4: createMainNotificationChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
@RequiresApi(Build.VERSION_CODES.O)
public void createMainNotificationChannel(Context c) {
String id = CHANNEL_ID;
String name = CHANNEL_NAME;
String description = CHANNEL_DESCRIPTION;
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription (description);
mChannel.enableLights(true);
mChannel.setLightColor( Color.RED);
mChannel.enableVibration(true);
NotificationManager mNotificationManager =
(NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
// NotificationManager mNotificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager
mNotificationManager.createNotificationChannel(mChannel);
}
示例5: createNotificationChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
private void createNotificationChannel() {
NotificationManager mNotificationManager =
(NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence name = getString(R.string.imagepipeline_notification_channel_name);
int importance =
NotificationManager
.IMPORTANCE_HIGH; // high importance shows the notification on the user screen.
NotificationChannel mChannel =
new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
mNotificationManager.createNotificationChannel(mChannel);
}
示例6: createChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
public static void createChannel(@NonNull Context context) {
Precondition.checkNotNull(context);
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
final NotificationManager manager = getManager(context);
manager.deleteNotificationChannel(CHANNEL_ID);
manager.createNotificationChannel(channel);
}
示例7: DefaultNotificationsPresenter
import android.app.NotificationManager; //导入方法依赖的package包/类
public DefaultNotificationsPresenter( App app )
{
this.app = app;
notificationManager =
(NotificationManager) app.getSystemService( Context.NOTIFICATION_SERVICE );
String favorite = app.getResources().getString( R.string.favorite );
// Since API 26 we need to manage notification channels
if ( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O )
{
Resources resources = app.getResources();
String channelId = resources.getString( R.string.notificationsChannelId );
String channelName = resources.getString( R.string.notificationsChannelName );
String channelDescription = resources.getString( R.string.notificationsChannelDescription );
NotificationChannel quotesChannel = new NotificationChannel(
channelId, channelName, NotificationManager.IMPORTANCE_LOW
);
quotesChannel.setDescription( channelDescription );
// Channel gets registered by systems and persists until app cache cleared or uninstalled.
// It is fine to recreate it on each app launch, because it won't change.
notificationManager.createNotificationChannel( quotesChannel );
// Use new builder with vector icon
notificationBuilder = new NotificationCompat.Builder( app, channelId )
.setSmallIcon( R.drawable.ic_format_quote_white_24dp )
.addAction( R.drawable.ic_favorite_white_24dp, favorite, createFavoriteActionIntent() );
}
else
{
// Use deprecated builder with image icon
notificationBuilder = new NotificationCompat.Builder( app )
.setSmallIcon( R.drawable.ic_format_quote_white_24dp_png )
.addAction( R.drawable.ic_favorite_white_24dp_png, favorite, createFavoriteActionIntent() );
}
notificationBuilder.setContentIntent( createContentIntent() );
notificationBuilder.setAutoCancel( true );
}
示例8: showNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void showNotification() {
final Intent notificationIntent = new Intent(mContext, EditContactActivity.class);
String CHANNEL_ID = "lead-management-ch";
notificationIntent.putExtra(
EditContactActivity.INTENT_EXTRA_CONTACT_NUM, number);
final PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
final NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.ic_call_black_24dp)
.setContentTitle("Call in Progress")
.setTicker("Lead Management")
.setContentIntent(contentIntent)
.setContentText("Number: " + number)
.setChannelId(CHANNEL_ID);
final NotificationManager manager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) {
manager.cancel(ID);
// check build version
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Lead-Management-Channel";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
manager.createNotificationChannel(mChannel);
}
manager.notify(ID, notification.build());
}
}
示例9: createNotificationChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = new NotificationChannel(
context.getString(R.string.file_op_channel_id),
context.getString(R.string.file_op_channel_name),
NotificationManager.IMPORTANCE_LOW);
mChannel.setDescription(context.getString(R.string.file_op_channel_description));
if (mNotificationManager != null) {
mNotificationManager.createNotificationChannel(mChannel);
}
}
示例10: onUsersDataReceived
import android.app.NotificationManager; //导入方法依赖的package包/类
private void onUsersDataReceived(Context context, int accountId, Owner owner, Bitmap bitmap) {
int ownerId = owner.getOwnerId();
final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if(Objects.isNull(manager)) {
return;
}
if (Utils.hasOreo()){
manager.createNotificationChannel(AppNotificationChannels.getBirthdaysChannel(context));
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.BIRTHDAYS_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_statusbar_birthday)
.setLargeIcon(bitmap)
.setContentTitle(context.getString(R.string.birthday))
.setContentText(owner.getFullName())
.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(Extra.PLACE, PlaceFactory.getOwnerWallPlace(accountId, ownerId, owner));
intent.setAction(MainActivity.ACTION_OPEN_PLACE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, ownerId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(contentIntent);
Notification notification = builder.build();
configOtherPushNotification(notification);
manager.notify(String.valueOf(ownerId), NotificationHelper.NOTIFICATION_BIRTHDAY, notification);
}
示例11: onCreate
import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
Fabric.with(this, new Crashlytics());
StringsManager.initialize();
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(Constants.TWITTER_CONSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET))
.debug(true)
.build();
Twitter.initialize(config);
//Create Notification channel in Android O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (notificationManager != null) {
NotificationChannel mChannel = new NotificationChannel("referendum",
StringsManager.getString("notification_channel_name"), NotificationManager.IMPORTANCE_HIGH);
mChannel.setDescription(StringsManager.getString("notification_channel_description"));
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
notificationManager.createNotificationChannel(mChannel);
}
}
}
示例12: notifyImpl
import android.app.NotificationManager; //导入方法依赖的package包/类
private void notifyImpl(Context context, User user, Bitmap bitmap) {
final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Utils.hasOreo()){
nManager.createNotificationChannel(AppNotificationChannels.getFriendRequestsChannel(context));
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.FRIEND_REQUESTS_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notify_statusbar)
.setLargeIcon(bitmap)
.setContentTitle(user.getFullName())
.setContentText(context.getString(R.string.subscribed_to_your_updates))
.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
int aid = Settings.get()
.accounts()
.getCurrent();
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(Extra.PLACE, PlaceFactory.getOwnerWallPlace(aid, uid, user));
intent.setAction(MainActivity.ACTION_OPEN_PLACE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, uid, intent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(contentIntent);
Notification notification = builder.build();
configOtherPushNotification(notification);
nManager.notify(String.valueOf(uid), NotificationHelper.NOTIFICATION_FRIEND_ID, notification);
}
示例13: createChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
/**
* Create notification channel for Android O
*/
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel() {
final CharSequence name = getString(R.string.channel_name);
final int importance = NotificationManager.IMPORTANCE_LOW;
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setShowBadge(false);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.enableVibration(false);
channel.enableLights(false);
channel.setBypassDnd(false);
final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.createNotificationChannel(channel);
}
示例14: onCreate
import android.app.NotificationManager; //导入方法依赖的package包/类
/**
* Called on service creation, sends a notification
*/
@Override
public void onCreate() {
sInstance = this;
mApp = (HavenApp)getApplication();
manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mPrefs = new PreferenceManager(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(channelId, channelName,
NotificationManager.IMPORTANCE_HIGH);
mChannel.setDescription(channelDescription);
mChannel.setLightColor(Color.RED);
mChannel.setImportance(NotificationManager.IMPORTANCE_MIN);
manager.createNotificationChannel(mChannel);
}
startSensors();
showNotification();
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
}
示例15: createNotificationChannel
import android.app.NotificationManager; //导入方法依赖的package包/类
private void createNotificationChannel() {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String id = ACCOUNT_TRANSFER_CHANNEL;
CharSequence name = "AccountTransfer";
String description = "Account Transfer";
int importance = NotificationManager.IMPORTANCE_MIN;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(false);
mChannel.enableVibration(false);
mNotificationManager.createNotificationChannel(mChannel);
}