當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。