Java Code Examples for android.app.NotificationManager#IMPORTANCE_MIN

The following examples show how to use android.app.NotificationManager#IMPORTANCE_MIN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntervalometerService.java    From timelapse-sony with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mBroadcastManager = LocalBroadcastManager.getInstance(this);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mCameraAPI = ((TimelapseApplication) getApplication()).getCameraAPI();

    mTimelapseData = ((TimelapseApplication) getApplication()).getTimelapseData();
    mApiRequestsList = mTimelapseData.getApiRequestsList();
    mStateMachineConnection = ((TimelapseApplication) getApplication()).
            getStateMachineConnection();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.channel_name);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_MIN;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        mChannel.setDescription(description);
        mChannel.enableLights(false);
        mChannel.enableVibration(false);
        mNotificationManager.createNotificationChannel(mChannel);
    }

}
 
Example 2
Source File: ApplicationEx.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannels() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationChannel foreground = new NotificationChannel("foreground", getString(R.string.channel_foreground), NotificationManager.IMPORTANCE_MIN);
    foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(foreground);

    NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT);
    notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(notify);

    NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT);
    access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(access);
}
 
Example 3
Source File: SecondScreenIntentService.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
@Override
public void startForeground() {
    String id = "SecondScreenIntentService";

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    CharSequence name = getString(R.string.background_operations);
    int importance = NotificationManager.IMPORTANCE_MIN;

    mNotificationManager.createNotificationChannel(new NotificationChannel(id, name, importance));

    // Build the notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, id)
            .setSmallIcon(R.drawable.ic_action_dock)
            .setContentTitle(getString(R.string.background_operations_active))
            .setOngoing(true)
            .setShowWhen(false);

    // Set notification color on Lollipop
    mBuilder.setColor(ContextCompat.getColor(this, R.color.primary_dark))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    startForeground(new Random().nextInt(), mBuilder.build());
}
 
Example 4
Source File: MainActivity.java    From FloatingView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // create default notification channel
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final String channelId = getString(R.string.default_floatingview_channel_id);
        final String channelName = getString(R.string.default_floatingview_channel_name);
        final NotificationChannel defaultChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
        final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (manager != null) {
            manager.createNotificationChannel(defaultChannel);
        }
    }

    if (savedInstanceState == null) {
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.container, FloatingViewControlFragment.newInstance());
        ft.commit();
    }
}
 
Example 5
Source File: TimingService.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * android 8.0 新增的notification channel这里需要做一个判断
 *
 * @param context
 */
public void initChannels(Context context) {
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }
    mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel("focus_pull_data",
            "Channel focus",
            NotificationManager.IMPORTANCE_MIN);
    channel.setDescription("更新订阅的数据");
    mNotificationManager.createNotificationChannel(channel);
}
 
Example 6
Source File: AccountTransferService.java    From account-transfer-api with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: NotificationSampleListener.java    From okdownload with Apache License 2.0 5 votes vote down vote up
public void initNotification() {
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    final String channelId = "okdownload";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationChannel channel = new NotificationChannel(
                channelId,
                "OkDownloadSample",
                NotificationManager.IMPORTANCE_MIN);
        manager.createNotificationChannel(channel);
    }

    builder = new NotificationCompat.Builder(context, channelId);


    builder.setDefaults(Notification.DEFAULT_LIGHTS)
            .setOngoing(true)
            .setOnlyAlertOnce(true)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setContentTitle("OkDownloadSample")
            .setContentText("Download a task showing on notification sample")
            .setSmallIcon(R.mipmap.ic_launcher);

    if (action != null) {
        builder.addAction(action);
    }
}
 
Example 8
Source File: ITagsService.java    From itag with GNU General Public License v3.0 5 votes vote down vote up
private static void createForegroundNotificationChannel(Context context) {
    if (!createdForegroundChannel && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = context.getString(R.string.app_name);
        int importance = NotificationManager.IMPORTANCE_MIN;
        NotificationChannel channel = new NotificationChannel(FOREGROUND_CHANNEL_ID, name, importance);
        channel.setSound(null, null);
        channel.setShowBadge(false);
        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
            createdForegroundChannel = true;
        }
    }
}
 
Example 9
Source File: NotificationHelper.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: NotificationHelper.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
            "Iota app name",
            NotificationManager.IMPORTANCE_MIN);
    notificationManager.createNotificationChannel(channel);
}
 
Example 11
Source File: ScreenshotDecorator.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.O)
private void ensureEvolvedNotificationChannel() {
    final NotificationChannel screenshotChannel = new NotificationChannel(
            CHANNEL_ID_SCREENSHOT,
            getString(R.string.noti_channel_screenshot),
            NotificationManager.IMPORTANCE_HIGH
    );
    screenshotChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build());
    screenshotChannel.enableLights(false);

    final NotificationChannel otherChannel = new NotificationChannel(
            CHANNEL_ID_OTHER,
            getString(R.string.noti_channel_other),
            NotificationManager.IMPORTANCE_DEFAULT
    );
    screenshotChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build());
    screenshotChannel.enableLights(true);

    final NotificationChannel previewedChannel = new NotificationChannel(
            CHANNEL_ID_PREVIEWED_SCREENSHOT,
            getString(R.string.noti_channel_screenshot_preview),
            NotificationManager.IMPORTANCE_MIN
    );
    previewedChannel.setSound(Uri.EMPTY, new AudioAttributes.Builder().build());
    previewedChannel.enableLights(false);

    createNotificationChannels(
            TARGET_PACKAGE, Arrays.asList(screenshotChannel, otherChannel, previewedChannel));
}
 
Example 12
Source File: DisplayConnectionService.java    From SecondScreen with Apache License 2.0 5 votes vote down vote up
@Override
public void startForeground() {
    // Intent to launch MainActivity when notification is clicked
    Intent mainActivityIntent = new Intent(this, MainActivity.class);
    PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    String id = "DisplayConnectionService";

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    CharSequence name = getString(R.string.auto_start);
    int importance = NotificationManager.IMPORTANCE_MIN;

    mNotificationManager.createNotificationChannel(new NotificationChannel(id, name, importance));

    // Build the notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, id)
            .setContentIntent(mainActivityPendingIntent)
            .setSmallIcon(R.drawable.ic_action_dock)
            .setContentTitle(getString(R.string.auto_start_active))
            .setOngoing(true)
            .setShowWhen(false);

    // Set notification color on Lollipop
    mBuilder.setColor(ContextCompat.getColor(this, R.color.primary_dark))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    startForeground(2, mBuilder.build());
}
 
Example 13
Source File: KeepAliveService.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
static private void createFgNotificationChannel(Context context) {
    if(!ch_created) {
        ch_created = true;
        NotificationChannel channel = new NotificationChannel(NotificationCenter.CH_PERMANENT,
            "Receive messages in background.", NotificationManager.IMPORTANCE_MIN); // IMPORTANCE_DEFAULT will play a sound
        channel.setDescription("Ensure reliable message receiving.");
        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}
 
Example 14
Source File: NotificationHandler.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
public NotificationHandler(Context context) {
    ((SyncthingApp) context.getApplicationContext()).component().inject(this);
    mContext = context;
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mPersistentChannel = new NotificationChannel(
                CHANNEL_PERSISTENT, mContext.getString(R.string.notifications_persistent_channel),
                NotificationManager.IMPORTANCE_MIN);
        mPersistentChannel.enableLights(false);
        mPersistentChannel.enableVibration(false);
        mPersistentChannel.setSound(null, null);
        mPersistentChannel.setShowBadge(false);
        mNotificationManager.createNotificationChannel(mPersistentChannel);

        mPersistentChannelWaiting = new NotificationChannel(
                CHANNEL_PERSISTENT_WAITING, mContext.getString(R.string.notification_persistent_waiting_channel),
                NotificationManager.IMPORTANCE_MIN);
        mPersistentChannelWaiting.enableLights(false);
        mPersistentChannelWaiting.enableVibration(false);
        mPersistentChannelWaiting.setSound(null, null);
        mPersistentChannelWaiting.setShowBadge(false);
        mNotificationManager.createNotificationChannel(mPersistentChannelWaiting);

        mInfoChannel = new NotificationChannel(
                CHANNEL_INFO, mContext.getString(R.string.notifications_other_channel),
                NotificationManager.IMPORTANCE_LOW);
        mPersistentChannel.enableVibration(false);
        mPersistentChannel.setSound(null, null);
        mPersistentChannel.setShowBadge(true);
        mNotificationManager.createNotificationChannel(mInfoChannel);
    } else {
        mPersistentChannel = null;
        mPersistentChannelWaiting = null;
        mInfoChannel = null;
    }
}
 
Example 15
Source File: LocationService.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
NotificationChannel getLocationNotificationChannel(Context context) {
    NotificationChannel channel = new NotificationChannel(
            GeometricWeather.NOTIFICATION_CHANNEL_ID_LOCATION,
            GeometricWeather.getNotificationChannelName(
                    context, GeometricWeather.NOTIFICATION_CHANNEL_ID_LOCATION),
            NotificationManager.IMPORTANCE_MIN);
    channel.setShowBadge(false);
    channel.setLightColor(ContextCompat.getColor(context, R.color.colorPrimary));
    return channel;
}
 
Example 16
Source File: ApplicationEx.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
private void createNotificationChannels() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Sync
        NotificationChannel service = new NotificationChannel(
                "service", getString(R.string.channel_service),
                NotificationManager.IMPORTANCE_MIN);
        service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
        service.setShowBadge(false);
        service.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
        nm.createNotificationChannel(service);

        // Send
        NotificationChannel send = new NotificationChannel(
                "send", getString(R.string.channel_send),
                NotificationManager.IMPORTANCE_DEFAULT);
        send.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
        send.setShowBadge(false);
        send.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        nm.createNotificationChannel(send);

        // Notify
        NotificationChannel notification = new NotificationChannel(
                "notification", getString(R.string.channel_notification),
                NotificationManager.IMPORTANCE_HIGH);
        notification.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        notification.enableLights(true);
        nm.createNotificationChannel(notification);

        // Update
        if (!Helper.isPlayStoreInstall()) {
            NotificationChannel update = new NotificationChannel(
                    "update", getString(R.string.channel_update),
                    NotificationManager.IMPORTANCE_HIGH);
            update.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
            update.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            nm.createNotificationChannel(update);
        }

        // Warnings
        NotificationChannel warning = new NotificationChannel(
                "warning", getString(R.string.channel_warning),
                NotificationManager.IMPORTANCE_HIGH);
        warning.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        nm.createNotificationChannel(warning);

        // Errors
        NotificationChannel error = new NotificationChannel(
                "error",
                getString(R.string.channel_error),
                NotificationManager.IMPORTANCE_HIGH);
        error.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        nm.createNotificationChannel(error);

        // Server alerts
        NotificationChannel alerts = new NotificationChannel(
                "alerts",
                getString(R.string.channel_alert),
                NotificationManager.IMPORTANCE_HIGH);
        alerts.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        nm.createNotificationChannel(alerts);

        // Contacts grouping
        NotificationChannelGroup group = new NotificationChannelGroup(
                "contacts",
                getString(R.string.channel_group_contacts));
        nm.createNotificationChannelGroup(group);
    }
}
 
Example 17
Source File: ForceDozeService.java    From ForceDoze with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    localDozeReceiver = new DozeReceiver();
    reloadSettingsReceiver = new ReloadSettingsReceiver();
    reloadNotificationBlocklistReceiver = new ReloadNotificationBlocklistReceiver();
    reloadAppsBlocklistReceiver = new ReloadAppsBlocklistReceiver();
    pendingIntentDozeReceiver = new PendingIntentDozeReceiver();
    enterDozeTimer = new Timer();
    enableSensorsTimer = new Timer();
    disableSensorsTimer = new Timer();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence statsName = getString(R.string.notification_channel_stats_name);
        String statsDescription = getString(R.string.notification_channel_stats_description);
        int statsImportance = NotificationManager.IMPORTANCE_MIN;
        NotificationChannel statsChannel = new NotificationChannel(CHANNEL_STATS, statsName, statsImportance);
        statsChannel.setDescription(statsDescription);

        CharSequence tipsName = getString(R.string.notification_channel_tips_name);
        String tipsDescription = getString(R.string.notification_channel_tips_description);
        int tipsImportance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel tipsChannel = new NotificationChannel(CHANNEL_TIPS, tipsName, tipsImportance);
        tipsChannel.setDescription(tipsDescription);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(statsChannel);
        notificationManager.createNotificationChannel(tipsChannel);
    }

    mStatsBuilder = new NotificationCompat.Builder(this, CHANNEL_STATS);
    pm = (PowerManager) getSystemService(POWER_SERVICE);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
    if (Utils.isDeviceRunningOnN()) {
        filter.addAction("android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED");
    }
    LocalBroadcastManager.getInstance(this).registerReceiver(reloadSettingsReceiver, new IntentFilter("reload-settings"));
    LocalBroadcastManager.getInstance(this).registerReceiver(reloadNotificationBlocklistReceiver, new IntentFilter("reload-notification-blocklist"));
    LocalBroadcastManager.getInstance(this).registerReceiver(reloadAppsBlocklistReceiver, new IntentFilter("reload-app-blocklist"));
    LocalBroadcastManager.getInstance(this).registerReceiver(pendingIntentDozeReceiver, new IntentFilter("reenter-doze"));
    this.registerReceiver(localDozeReceiver, filter);
    turnOffDataInDoze = getDefaultSharedPreferences(getApplicationContext()).getBoolean("turnOffDataInDoze", false);
    turnOffWiFiInDoze = getDefaultSharedPreferences(getApplicationContext()).getBoolean("turnOffWiFiInDoze", false);
    ignoreLockscreenTimeout = getDefaultSharedPreferences(getApplicationContext()).getBoolean("ignoreLockscreenTimeout", true);
    useXposedSensorWorkaround = getDefaultSharedPreferences(getApplicationContext()).getBoolean("useXposedSensorWorkaround", false);
    useNonRootSensorWorkaround = getDefaultSharedPreferences(getApplicationContext()).getBoolean("useNonRootSensorWorkaround", false);
    dozeEnterDelay = getDefaultSharedPreferences(getApplicationContext()).getInt("dozeEnterDelay", 0);
    useAutoRotateAndBrightnessFix = getDefaultSharedPreferences(getApplicationContext()).getBoolean("autoRotateAndBrightnessFix", false);
    sensorWhitelistPackage = getDefaultSharedPreferences(getApplicationContext()).getString("sensorWhitelistPackage", "");
    enableSensors = getDefaultSharedPreferences(getApplicationContext()).getBoolean("enableSensors", false);
    disableWhenCharging = getDefaultSharedPreferences(getApplicationContext()).getBoolean("disableWhenCharging", true);
    isSuAvailable = getDefaultSharedPreferences(getApplicationContext()).getBoolean("isSuAvailable", false);
    showPersistentNotif = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("showPersistentNotif", true);
    dozeUsageData = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getStringSet("dozeUsageDataAdvanced", new LinkedHashSet<String>());
    dozeNotificationBlocklist = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getStringSet("notificationBlockList", new LinkedHashSet<String>());
    dozeAppBlocklist = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getStringSet("dozeAppBlockList", new LinkedHashSet<String>());

    if (!Utils.isDumpPermissionGranted(getApplicationContext())) {
        if (isSuAvailable) {
            grantDumpPermission();
        }
    }

    if (Utils.isDeviceRunningOnN()) {
        if (!Utils.isSecureSettingsPermissionGranted(getApplicationContext())) {
            if (isSuAvailable) {
                grantSecureSettingsPermission();
            }
        }
    }

    if (!Utils.isReadPhoneStatePermissionGranted(getApplicationContext())) {
        if (isSuAvailable) {
            grantReadPhoneStatePermission();
        }
    }

    // To initialize root shell/shell on service start
    if (isSuAvailable) {
        executeCommandWithRoot("whoami");
    } else {
        executeCommand("whoami");
    }
}
 
Example 18
Source File: NotificationService.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
void initializeChannels() {
    final Context c = mXmppConnectionService;
    final NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("status", c.getString(R.string.notification_group_status_information)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("chats", c.getString(R.string.notification_group_messages)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("calls", c.getString(R.string.notification_group_calls)));
    final NotificationChannel foregroundServiceChannel = new NotificationChannel(FOREGROUND_CHANNEL_ID,
            c.getString(R.string.foreground_service_channel_name),
            NotificationManager.IMPORTANCE_MIN);
    foregroundServiceChannel.setDescription(c.getString(R.string.foreground_service_channel_description));
    foregroundServiceChannel.setShowBadge(false);
    foregroundServiceChannel.setGroup("status");
    notificationManager.createNotificationChannel(foregroundServiceChannel);

    final NotificationChannel backupChannel = new NotificationChannel(BACKUP_CHANNEL_ID,
            c.getString(R.string.backup_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    backupChannel.setShowBadge(false);
    backupChannel.setGroup("status");
    notificationManager.createNotificationChannel(backupChannel);

    final NotificationChannel videoCompressionChannel = new NotificationChannel(VIDEOCOMPRESSION_CHANNEL_ID,
            c.getString(R.string.video_compression_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    videoCompressionChannel.setShowBadge(false);
    videoCompressionChannel.setGroup("status");
    notificationManager.createNotificationChannel(videoCompressionChannel);

    final NotificationChannel AppUpdateChannel = new NotificationChannel(UPDATE_CHANNEL_ID,
            c.getString(R.string.app_update_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    AppUpdateChannel.setShowBadge(false);
    AppUpdateChannel.setGroup("status");
    notificationManager.createNotificationChannel(AppUpdateChannel);

    final NotificationChannel incomingCallsChannel = new NotificationChannel("incoming_calls",
            c.getString(R.string.incoming_calls_channel_name),
            NotificationManager.IMPORTANCE_HIGH);
    incomingCallsChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
            .build());
    incomingCallsChannel.setShowBadge(false);
    incomingCallsChannel.setLightColor(LED_COLOR);
    incomingCallsChannel.enableLights(true);
    incomingCallsChannel.setGroup("calls");
    incomingCallsChannel.setBypassDnd(true);
    incomingCallsChannel.enableVibration(true);
    incomingCallsChannel.setVibrationPattern(CALL_PATTERN);
    notificationManager.createNotificationChannel(incomingCallsChannel);

    final NotificationChannel ongoingCallsChannel = new NotificationChannel("ongoing_calls",
            c.getString(R.string.ongoing_calls_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    ongoingCallsChannel.setShowBadge(false);
    ongoingCallsChannel.setGroup("calls");
    notificationManager.createNotificationChannel(ongoingCallsChannel);


    final NotificationChannel messagesChannel = new NotificationChannel("messages",
            c.getString(R.string.messages_channel_name),
            NotificationManager.IMPORTANCE_HIGH);
    messagesChannel.setShowBadge(true);
    messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
            .build());
    messagesChannel.setLightColor(LED_COLOR);
    final int dat = 70;
    final long[] pattern = {0, 3 * dat, dat, dat};
    messagesChannel.setVibrationPattern(pattern);
    messagesChannel.enableVibration(true);
    messagesChannel.enableLights(true);
    messagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(messagesChannel);

    final NotificationChannel silentMessagesChannel = new NotificationChannel("silent_messages",
            c.getString(R.string.silent_messages_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    silentMessagesChannel.setDescription(c.getString(R.string.silent_messages_channel_description));
    silentMessagesChannel.setShowBadge(true);
    silentMessagesChannel.setLightColor(LED_COLOR);
    silentMessagesChannel.enableLights(true);
    silentMessagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(silentMessagesChannel);

    final NotificationChannel quietHoursChannel = new NotificationChannel("quiet_hours",
            c.getString(R.string.title_pref_quiet_hours),
            NotificationManager.IMPORTANCE_LOW);
    quietHoursChannel.setShowBadge(true);
    quietHoursChannel.setLightColor(LED_COLOR);
    quietHoursChannel.enableLights(true);
    quietHoursChannel.setGroup("chats");
    quietHoursChannel.enableVibration(false);
    quietHoursChannel.setSound(null, null);
    notificationManager.createNotificationChannel(quietHoursChannel);
}
 
Example 19
Source File: Monitor.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
@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.data_sharing), NotificationManager.IMPORTANCE_MIN);
        notificationManager.createNotificationChannel(notificationChannel);

        PendingIntent disableIntent = PendingIntent.getBroadcast(this, 1,
                new Intent(this, DisableReceiver.class),
                PendingIntent.FLAG_UPDATE_CURRENT);

        Intent launchIntent = new Intent(this, MainActivity.class);
        launchIntent.setAction(Intent.ACTION_VIEW);
        launchIntent.putExtra(NavigationActivity.INTENT_SECTION,
                DataSharingFragment.class.getCanonicalName());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                launchIntent, 0);

        Notification.Builder builder =
                new Notification.Builder(this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.data_sharing))
                .setContentText(getString(R.string.data_sharing_summary_notification))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(contentIntent)
                .addAction(0, getString(R.string.disable), disableIntent);
        startForeground(NotificationId.MONITOR, builder.build());
    }

    registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    IntentFilter screenFilter = new IntentFilter();
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenFilter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(mScreenReceiver, screenFilter);

    mScreenOn = Utils.isScreenOn(this);
}
 
Example 20
Source File: FIRMessagingModule.java    From react-native-fcm with MIT License 4 votes vote down vote up
@ReactMethod
public void createNotificationChannel(ReadableMap details, Promise promise){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager mngr = (NotificationManager) getReactApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        String id = details.getString("id");
        String name = details.getString("name");
        String priority = details.getString("priority");
        int importance;
        switch(priority) {
            case "min":
                importance = NotificationManager.IMPORTANCE_MIN;
                break;
            case "low":
                importance = NotificationManager.IMPORTANCE_LOW;
                break;
            case "high":
                importance = NotificationManager.IMPORTANCE_HIGH;
                break;
            case "max":
                importance = NotificationManager.IMPORTANCE_MAX;
                break;
            default:
                importance = NotificationManager.IMPORTANCE_DEFAULT;
        }
        if (mngr.getNotificationChannel(id) != null) {
            promise.resolve(null);
            return;
        }
        //
        NotificationChannel channel = new NotificationChannel(
                id,
                name,
                importance);
        // Configure the notification channel.
        if(details.hasKey("description")){
            channel.setDescription(details.getString("description"));
        }
        mngr.createNotificationChannel(channel);
    }
    promise.resolve(null);
}