Search in sources :

Example 61 with NotificationChannel

use of android.app.NotificationChannel in project schedule_notifications by serralvo.

the class AlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String title = intent.getStringExtra(IntentConstants.TITLE_PARAM);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.createNotificationChannel(channel);
    }
    Intent actionIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    PendingIntent actionPendingIntent = PendingIntent.getActivity(context, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID).setSmallIcon(NotificationSingleton.getInstance().getNotificationIcon()).setContentTitle(title).setContentIntent(actionPendingIntent).setAutoCancel(true).setPriority(NotificationCompat.PRIORITY_DEFAULT);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 62 with NotificationChannel

use of android.app.NotificationChannel in project PhoneProfilesPlus by henrichg.

the class PPApplication method createGrantPermissionNotificationChannel.

static void createGrantPermissionNotificationChannel(Context context) {
    if (Build.VERSION.SDK_INT >= 26) {
        // The user-visible name of the channel.
        CharSequence name = context.getString(R.string.notification_channel_grant_permission);
        // The user-visible description of the channel.
        String description = context.getString(R.string.notification_channel_grant_permission_description);
        NotificationChannel channel = new NotificationChannel(GRANT_PERMISSION_NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_DEFAULT);
        // Configure the notification channel.
        // channel.setImportance(importance);
        channel.setDescription(description);
        channel.enableLights(false);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        // channel.setLightColor(Color.RED);
        channel.enableVibration(false);
        // channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null)
            notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 63 with NotificationChannel

use of android.app.NotificationChannel in project PhoneProfilesPlus by henrichg.

the class PPApplication method createInformationNotificationChannel.

static void createInformationNotificationChannel(Context context) {
    if (Build.VERSION.SDK_INT >= 26) {
        // The user-visible name of the channel.
        CharSequence name = context.getString(R.string.notification_channel_information);
        // The user-visible description of the channel.
        String description = context.getString(R.string.empty_string);
        NotificationChannel channel = new NotificationChannel(INFORMATION_NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_LOW);
        // Configure the notification channel.
        // channel.setImportance(importance);
        channel.setDescription(description);
        channel.enableLights(false);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        // channel.setLightColor(Color.RED);
        channel.enableVibration(false);
        // channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null)
            notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 64 with NotificationChannel

use of android.app.NotificationChannel in project PhoneProfilesPlus by henrichg.

the class PPApplication method createProfileNotificationChannel.

// --------------------------------
// notification channels -------------------------
static void createProfileNotificationChannel(/*Profile profile, */
Context context) {
    if (Build.VERSION.SDK_INT >= 26) {
        // no sound
        /*int importance = NotificationManager.IMPORTANCE_LOW;
            if (ApplicationPreferences.notificationShowInStatusBar(context)) {
                KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
                if (myKM != null) {
                    //boolean screenUnlocked = !myKM.inKeyguardRestrictedInputMode();
                    //boolean screenUnlocked = getScreenUnlocked(context);
                    boolean screenUnlocked = !myKM.isKeyguardLocked();
                    if ((ApplicationPreferences.notificationHideInLockScreen(context) && (!screenUnlocked)) ||
                            ((profile != null) && profile._hideStatusBarIcon))
                        importance = NotificationManager.IMPORTANCE_MIN;
                }
            } else
                importance = NotificationManager.IMPORTANCE_MIN;*/
        // The user-visible name of the channel.
        CharSequence name = context.getString(R.string.notification_channel_activated_profile);
        // The user-visible description of the channel.
        String description = context.getString(R.string.notification_channel_activated_profile_description_ppp);
        NotificationChannel channel = new NotificationChannel(PROFILE_NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_LOW);
        // Configure the notification channel.
        // channel.setImportance(importance);
        channel.setDescription(description);
        channel.enableLights(false);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        // channel.setLightColor(Color.RED);
        channel.enableVibration(false);
        // channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null)
            notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 65 with NotificationChannel

use of android.app.NotificationChannel in project PhoneProfilesPlus by henrichg.

the class PPApplication method createExclamationNotificationChannel.

static void createExclamationNotificationChannel(Context context) {
    if (Build.VERSION.SDK_INT >= 26) {
        // The user-visible name of the channel.
        CharSequence name = context.getString(R.string.notification_channel_exclamation);
        // The user-visible description of the channel.
        String description = context.getString(R.string.empty_string);
        NotificationChannel channel = new NotificationChannel(EXCLAMATION_NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_DEFAULT);
        // Configure the notification channel.
        // channel.setImportance(importance);
        channel.setDescription(description);
        channel.enableLights(false);
        // Sets the notification light color for notifications posted to this
        // channel, if the device supports this feature.
        // channel.setLightColor(Color.RED);
        channel.enableVibration(false);
        // channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null)
            notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Aggregations

NotificationChannel (android.app.NotificationChannel)762 Test (org.junit.Test)430 NotificationBackend (com.android.settings.notification.NotificationBackend)215 NotificationManager (android.app.NotificationManager)210 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)114 Intent (android.content.Intent)87 Preference (androidx.preference.Preference)76 PendingIntent (android.app.PendingIntent)73 NotificationChannelGroup (android.app.NotificationChannelGroup)54 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)43 ArrayList (java.util.ArrayList)34 TargetApi (android.annotation.TargetApi)32 AudioAttributes (android.media.AudioAttributes)31 RequiresApi (android.support.annotation.RequiresApi)28 RequiresApi (androidx.annotation.RequiresApi)25 Uri (android.net.Uri)21 RestrictedListPreference (com.android.settings.RestrictedListPreference)20 SuppressLint (android.annotation.SuppressLint)19 ShortcutInfo (android.content.pm.ShortcutInfo)19