当前位置: 首页>>代码示例>>Java>>正文


Java NotificationChannel类代码示例

本文整理汇总了Java中android.app.NotificationChannel的典型用法代码示例。如果您正苦于以下问题:Java NotificationChannel类的具体用法?Java NotificationChannel怎么用?Java NotificationChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NotificationChannel类属于android.app包,在下文中一共展示了NotificationChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldBeFilteredOut

import android.app.NotificationChannel; //导入依赖的package包/类
private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
    Notification notification = sbn.getNotification();

    if (AndroidVersion.isAtLeastOreo()) {
        getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
        if (!mTempRanking.canShowBadge()) {
            return true;
        }
        if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            // Special filtering for the default, legacy "Miscellaneous" channel.
            if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
                return true;
            }
        }
    }

    if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
        return true;
    }

    boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
    CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
    CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
    boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
    return (isGroupHeader || missingTitleAndText);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:27,代码来源:NotificationListener.java

示例2: onCreate

import android.app.NotificationChannel; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
                getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.setSound(null, null);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder builder = new Notification.Builder(
                this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.apply_on_boot))
                .setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationId.APPLY_ON_BOOT, builder.build());
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:20,代码来源:ApplyOnBootService.java

示例3: onCreate

import android.app.NotificationChannel; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
                .setOnAudioFocusChangeListener(audioFocusChangeListener)
                .setAcceptsDelayedFocusGain(false)
                .setWillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
 
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:43,代码来源:PlayerService.java

示例4: createNotificationChannel

import android.app.NotificationChannel; //导入依赖的package包/类
@TargetApi(26)
private void createNotificationChannel() {

    notificationChannelClass = new NotificationChannel("class", "Class Notifications", NotificationManager.IMPORTANCE_LOW);
    notificationChannelClass.setDescription("Notifications about classes.");
    notificationChannelClass.enableLights(false);
    notificationChannelClass.enableVibration(false);
    notificationChannelClass.setBypassDnd(false);
    notificationChannelClass.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelClass.setShowBadge(false);

    notificationManager.createNotificationChannel(notificationChannelClass);

    notificationChannelReminder = new NotificationChannel("reminder", "Reminders", NotificationManager.IMPORTANCE_MAX);
    notificationChannelReminder.setDescription("Notifications about events.");
    notificationChannelReminder.enableLights(true);
    notificationChannelReminder.setLightColor(sharedPreferences.getInt("primary_color", ContextCompat.getColor(this, R.color.teal)));
    notificationChannelReminder.enableVibration(true);
    notificationChannelReminder.setBypassDnd(true);
    notificationChannelReminder.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelReminder.setShowBadge(true);

    notificationManager.createNotificationChannel(notificationChannelReminder);

}
 
开发者ID:arminghofrani,项目名称:chalkboard,代码行数:26,代码来源:Background.java

示例5: createNotificationChannelForAndroidO

import android.app.NotificationChannel; //导入依赖的package包/类
private void createNotificationChannelForAndroidO() {
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mNotificationManager != null) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                "Nova Music Player", NotificationManager.IMPORTANCE_LOW);

        // Configure the notification channel.
        notificationChannel.setDescription("Channel of Nova Music Player");
        notificationChannel.enableLights(false);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.setSound(null, null);
        notificationChannel.enableVibration(false);
        notificationChannel.setShowBadge(false);
        mNotificationManager.createNotificationChannel(notificationChannel);
    }
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:17,代码来源:NovaNotificationManager.java

示例6: createChannel

import android.app.NotificationChannel; //导入依赖的package包/类
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel() {
    if (mNotificationManager.getNotificationChannel(CHANNEL_ID) == null) {
        // The user-visible name of the channel.
        CharSequence name = "MediaSession";
        // The user-visible description of the channel.
        String description = "MediaSession and MediaPlayer";
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        // Configure the notification channel.
        mChannel.setDescription(description);
        mChannel.enableLights(true);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        mChannel.setLightColor(Color.RED);
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(
                new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mNotificationManager.createNotificationChannel(mChannel);
        Log.d(TAG, "createChannel: New channel created");
    } else {
        Log.d(TAG, "createChannel: Existing channel reused");
    }
}
 
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:25,代码来源:MediaNotificationManager.java

示例7: initNotificationManager

import android.app.NotificationChannel; //导入依赖的package包/类
private void initNotificationManager() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final Stopwatch watch = Stopwatch.createStarted();
        final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        final NotificationChannel received = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_RECEIVED,
                getString(R.string.notification_channel_received_name), NotificationManager.IMPORTANCE_DEFAULT);
        received.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received),
                new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build());
        nm.createNotificationChannel(received);

        final NotificationChannel ongoing = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_ONGOING,
                getString(R.string.notification_channel_ongoing_name), NotificationManager.IMPORTANCE_LOW);
        nm.createNotificationChannel(ongoing);

        final NotificationChannel important = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_IMPORTANT,
                getString(R.string.notification_channel_important_name), NotificationManager.IMPORTANCE_HIGH);
        nm.createNotificationChannel(important);

        log.info("created notification channels, took {}", watch);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:WalletApplication.java

示例8: CreateChannel

import android.app.NotificationChannel; //导入依赖的package包/类
public static void CreateChannel(String identifier, String name, String description, int importance, String soundName, int enableLights, int lightColor, int enableVibration, long[] vibrationPattern, String bundle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;

    channels.add(identifier);

    NotificationManager nm = (NotificationManager) UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel(identifier, name, importance);
    channel.setDescription(description);
    if (soundName != null) {
        Resources res = UnityPlayer.currentActivity.getResources();
        int id = res.getIdentifier("raw/" + soundName, null, UnityPlayer.currentActivity.getPackageName());
        AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
        channel.setSound(Uri.parse("android.resource://" + bundle + "/" + id), audioAttributes);
    }
    channel.enableLights(enableLights == 1);
    channel.setLightColor(lightColor);
    channel.enableVibration(enableVibration == 1);
    if (vibrationPattern == null)
        vibrationPattern = new long[] { 1000L, 1000L };
    channel.setVibrationPattern(vibrationPattern);
    nm.createNotificationChannel(channel);
}
 
开发者ID:Agasper,项目名称:unity-android-notifications,代码行数:24,代码来源:UnityNotificationManager.java

示例9: testCreateChannel_overridesPrevious

import android.app.NotificationChannel; //导入依赖的package包/类
@Test
@SdkSuppress(minSdkVersion = O)
public void testCreateChannel_overridesPrevious(){
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.deleteNotificationChannel("ems_me_default");
    assertNull(manager.getNotificationChannel("ems_me_default"));
    MessagingServiceUtils.createDefaultChannel(context, enabledOreoConfig);
    NotificationChannel channel = manager.getNotificationChannel("ems_me_default");
    assertNotNull(channel);

    OreoConfig updatedConfig = new OreoConfig(true, "updatedName", "updatedDescription");
    MessagingServiceUtils.createDefaultChannel(context, updatedConfig);

    NotificationChannel updatedChannel = manager.getNotificationChannel("ems_me_default");
    assertEquals(updatedConfig.getDefaultChannelName(), updatedChannel.getName());
    assertEquals(updatedConfig.getDefaultChannelDescription(), updatedChannel.getDescription());
}
 
开发者ID:emartech,项目名称:android-mobile-engage-sdk,代码行数:18,代码来源:MessagingServiceUtilsTest.java

示例10: onCreate

import android.app.NotificationChannel; //导入依赖的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());
    }

}
 
开发者ID:ShreyanshLodha,项目名称:BlueBolt-Kernel-Tweaking-app,代码行数:29,代码来源:ProximityService.java

示例11: createNotificationChannel

import android.app.NotificationChannel; //导入依赖的package包/类
@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(){
    String channelId = "VBrowserNotification";
    String channelName = "前台下载通知";
    NotificationChannel chan = new NotificationChannel(channelId,
            channelName, NotificationManager.IMPORTANCE_HIGH);
    chan.setLightColor(Color.BLUE);
    chan.setImportance(NotificationManager.IMPORTANCE_NONE);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
    return channelId;
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:14,代码来源:DownloadForegroundService.java

示例12: showNotification

import android.app.NotificationChannel; //导入依赖的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());
    }
}
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:17,代码来源:CacheService.java

示例13: createMainNotificationChannel

import android.app.NotificationChannel; //导入依赖的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);
}
 
开发者ID:smtrz,项目名称:GPSTracker-Android,代码行数:17,代码来源:NotificationClass.java

示例14: Notify

import android.app.NotificationChannel; //导入依赖的package包/类
public Notify(Context context, int ID) {
    this.NOTIFICATION_ID = ID;
    mContext = context;
    // 获取系统服务来初始化对象
    nm = (NotificationManager) mContext
            .getSystemService(NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        cBuilder = new NotificationCompat.Builder(mContext, mChannelId = mContext.getPackageName().concat(AGENTWEB_VERSION));
        NotificationChannel mNotificationChannel = new NotificationChannel(mChannelId, AgentWebUtils.getApplicationName(context), NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
        mNotificationManager.createNotificationChannel(mNotificationChannel);
    } else {
        cBuilder = new NotificationCompat.Builder(mContext);
    }
}
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:17,代码来源:Notify.java

示例15: report

import android.app.NotificationChannel; //导入依赖的package包/类
public void report(CrashViewModel crashViewModel) {
  Notification notification = notification(crashViewModel);

  NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(
        CHANNEL_ID,
        "Sherlock",
        IMPORTANCE_DEFAULT
    );
    notificationManager.createNotificationChannel(channel);
  }

  notificationManager.notify(crashViewModel.getIdentifier(), notification);
}
 
开发者ID:ajitsing,项目名称:Sherlock,代码行数:17,代码来源:CrashReporter.java


注:本文中的android.app.NotificationChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。