Java Code Examples for android.app.NotificationManager#IMPORTANCE_DEFAULT
The following examples show how to use
android.app.NotificationManager#IMPORTANCE_DEFAULT .
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: RNPushNotificationHelper.java From react-native-push-notification-CE with MIT License | 6 votes |
private static void checkOrCreateChannel(NotificationManager manager) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; if (channelCreated) return; if (manager == null) return; final CharSequence name = "Notifications"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance); channel.enableLights(true); channel.enableVibration(true); manager.createNotificationChannel(channel); channelCreated = true; }
Example 2
Source File: OngoingCallActivity.java From call_manage with MIT License | 6 votes |
/** * Creates the notification channel * Which allows and manages the displaying of the notification */ private void createNotificationChannel() { // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library 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_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance // or other notification behaviors after this mNotificationManager = getSystemService(NotificationManager.class); mNotificationManager.createNotificationChannel(channel); } }
Example 3
Source File: DownloadNotificationChannel.java From Hentoid with Apache License 2.0 | 6 votes |
public static void init(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String name = "Book downloads"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(ID, name, importance); channel.setSound(null, null); channel.setVibrationPattern(null); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); // Mandatory; it is not possible to change the sound of an existing channel after its initial creation Objects.requireNonNull(notificationManager, "notificationManager must not be null"); notificationManager.deleteNotificationChannel(ID_OLD); notificationManager.createNotificationChannel(channel); } }
Example 4
Source File: ImportNotificationChannel.java From Hentoid with Apache License 2.0 | 6 votes |
public static void init(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String name = "Library imports"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(ID, name, importance); channel.setSound(null, null); channel.setVibrationPattern(null); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); // Mandatory; it is not possible to change the sound of an existing channel after its initial creation Objects.requireNonNull(notificationManager, "notificationManager must not be null"); notificationManager.deleteNotificationChannel(ID_OLD); notificationManager.createNotificationChannel(channel); } }
Example 5
Source File: NotificationHelper.java From NekoSMS with GNU General Public License v3.0 | 5 votes |
public static void createNotificationChannel(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } String name = context.getString(R.string.channel_blocked_messages); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, name, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); }
Example 6
Source File: CrashUtil.java From CrashReporter with Apache License 2.0 | 5 votes |
private static void createNotificationChannel(NotificationManager notificationManager, Context context) { if (Build.VERSION.SDK_INT >= 26) { CharSequence name = context.getString(R.string.notification_crash_report_title); String description = ""; NotificationChannel channel = new NotificationChannel(CHANNEL_NOTIFICATION_ID, name, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(description); notificationManager.createNotificationChannel(channel); } }
Example 7
Source File: LocationUpdatesService.java From location-samples with Apache License 2.0 | 5 votes |
@Override public void onCreate() { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); mLocationCallback = new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); onNewLocation(locationResult.getLastLocation()); } }; createLocationRequest(); getLastLocation(); HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mServiceHandler = new Handler(handlerThread.getLooper()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Android O requires a Notification Channel. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.app_name); // Create the channel for the notification NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT); // Set the Notification Channel for the Notification Manager. mNotificationManager.createNotificationChannel(mChannel); } }
Example 8
Source File: NotifyManager.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
private void createNotifyChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (mNotificationManager != null) { mNotificationManager.createNotificationChannelGroup( new NotificationChannelGroup(mGroupId, mGroupName)); NotificationChannel channelMsg = new NotificationChannel(mChannelMsgId, mChannelMsgName, NotificationManager.IMPORTANCE_DEFAULT); channelMsg.setDescription(mChannelMsgDes); channelMsg.enableLights(true); channelMsg.setLightColor(Color.BLUE); channelMsg.enableVibration(false); channelMsg.setVibrationPattern(new long[] { 100, 200, 300, 400 }); channelMsg.setShowBadge(true); channelMsg.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); channelMsg.setGroup(mGroupId); mNotificationManager.createNotificationChannel(channelMsg); NotificationChannel channelService = new NotificationChannel(mChannelServiceId, mChannelServiceName, NotificationManager.IMPORTANCE_LOW); channelService.setDescription(mChannelServiceDes); channelService.enableLights(false); channelService.enableVibration(false); channelService.setShowBadge(false); channelService.setSound(null, null); channelService.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); channelService.setGroup(mGroupId); mNotificationManager.createNotificationChannel(channelService); } } }
Example 9
Source File: UpdaterNotificationHelper.java From TowerCollector with Mozilla Public License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.O) private void createNotificationChannel(NotificationManager notificationManager) { NotificationChannel channel = new NotificationChannel( OTHER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.other_notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); }
Example 10
Source File: LocationResultHelper.java From background-location-updates-android-o with Apache License 2.0 | 5 votes |
LocationResultHelper(Context context, List<Location> locations) { mContext = context; mLocations = locations; NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL, context.getString(R.string.default_channel), NotificationManager.IMPORTANCE_DEFAULT); channel.setLightColor(Color.GREEN); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); getNotificationManager().createNotificationChannel(channel); }
Example 11
Source File: LocationForegroundService.java From rn-background-location with MIT License | 5 votes |
private void createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel serviceChannel = new NotificationChannel( CHANNEL_ID, "Foreground Service Channel", NotificationManager.IMPORTANCE_DEFAULT ); NotificationManager manager = getSystemService(NotificationManager.class); manager.createNotificationChannel(serviceChannel); } }
Example 12
Source File: NotificationController.java From MiPushFramework with GNU General Public License v3.0 | 5 votes |
@TargetApi(26) private static NotificationChannel createChannelWithPackage(@NonNull String packageName, @NonNull CharSequence name) { NotificationChannel channel = new NotificationChannel(getChannelIdByPkg(packageName), name, NotificationManager.IMPORTANCE_DEFAULT); channel.enableVibration(true); return channel; }
Example 13
Source File: NotificationFactory.java From PresencePublisher with MIT License | 5 votes |
public static void createNotificationChannel(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = context.getSystemService(NotificationManager.class); if (notificationManager != null) { NotificationChannel channel = new NotificationChannel(context.getPackageName(), context.getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } } }
Example 14
Source File: NotificationsService.java From ForPDA with GNU General Public License v3.0 | 4 votes |
public void sendNotification(NotificationEvent event, Bitmap avatar) { eventsHistory.put(event.notifyId(), event); String title = createTitle(event); String text = createContent(event); String summaryText = createSummary(event); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(title); bigTextStyle.bigText(text); bigTextStyle.setSummaryText(summaryText); String channelId = getChannelId(event); String channelName = getChannelName(event); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT); getSystemService(NotificationManager.class).createNotificationChannel(channel); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId); if (avatar != null && !event.fromSite()) { builder.setLargeIcon(avatar); } builder.setSmallIcon(createSmallIcon(event)); builder.setContentTitle(title); builder.setContentText(text); builder.setStyle(bigTextStyle); builder.setChannelId(channelId); Intent notifyIntent = new Intent(this, MainActivity.class); notifyIntent.setData(Uri.parse(createIntentUrl(event))); notifyIntent.setAction(Intent.ACTION_VIEW); PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0); builder.setContentIntent(notifyPendingIntent); configureNotification(builder); mNotificationManager.cancel(event.notifyId()); mNotificationManager.notify(event.notifyId(), builder.build()); }
Example 15
Source File: IpcService.java From OneTapVideoDownload with GNU General Public License v3.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.O) private NotificationChannel getNotificationChannel() { return new NotificationChannel(PACKAGE_NAME, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); }
Example 16
Source File: UpdateService.java From FacebookNotifications with MIT License | 4 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private Notification.Builder getNewStyleNotification(int smallIcon, Bitmap largeIcon, String title, String text, int priority, Intent resultIntent, int notifType, String soundURI, long[] vibrationPattern) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.R_string_notif_channel_name); String description = getString(R.string.notif_channel_description); int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); // 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(channel); } Notification.Builder mBuilder = new Notification.Builder(getApplicationContext()) .setSmallIcon(smallIcon) .setLargeIcon(largeIcon) .setContentTitle(title) .setContentText(text) .setPriority(priority) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mBuilder.setChannelId(CHANNEL_ID); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setCategory(Notification.CATEGORY_SOCIAL) .setVisibility(Notification.VISIBILITY_PRIVATE); } TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (soundURI != null) { Uri uri = Uri.parse(soundURI); mBuilder.setSound(uri); } mBuilder.setVibrate(vibrationPattern); return mBuilder; }
Example 17
Source File: VoiceFirebaseMessagingService.java From cordova-plugin-twiliovoicesdk with MIT License | 4 votes |
private void notify(CallInvite callInvite, int notificationId) { String callSid = callInvite.getCallSid(); Notification notification = null; Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName()); intent.setAction(TwilioVoicePlugin.ACTION_INCOMING_CALL); intent.putExtra(TwilioVoicePlugin.INCOMING_CALL_NOTIFICATION_ID, notificationId); intent.putExtra(TwilioVoicePlugin.INCOMING_CALL_INVITE, callInvite); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_CANCEL_CURRENT); Bundle extras = new Bundle(); extras.putInt(NOTIFICATION_ID_KEY, notificationId); extras.putString(CALL_SID_KEY, callSid); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel callInviteChannel = new NotificationChannel(VOICE_CHANNEL, "Primary Voice Channel", NotificationManager.IMPORTANCE_DEFAULT); callInviteChannel.setLightColor(Color.RED); callInviteChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); notificationManager.createNotificationChannel(callInviteChannel); notification = buildNotification(callInvite.getFrom() + " is calling", pendingIntent, extras); notificationManager.notify(notificationId, notification); } else { int iconIdentifier = getResources().getIdentifier("icon", "mipmap", getPackageName()); int incomingCallAppNameId = (int) getResources().getIdentifier("incoming_call_app_name", "string", getPackageName()); String contentTitle = getString(incomingCallAppNameId); if (contentTitle == null) { contentTitle = "Incoming Call"; } final String from = callInvite.getFrom() + " is calling"; NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(iconIdentifier) .setContentTitle(contentTitle) .setContentText(from) .setAutoCancel(true) .setExtras(extras) .setContentIntent(pendingIntent) .setGroup("voice_app_notification") .setColor(Color.rgb(225, 0, 0)); notificationManager.notify(notificationId, notificationBuilder.build()); } }
Example 18
Source File: App.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 4 votes |
private void CreateNotificationChannels() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //Channel 1 Configuration NotificationChannel channel1 = new NotificationChannel(CHANNEL_1_ID, "channel 1",NotificationManager.IMPORTANCE_HIGH); channel1.setDescription("Test Channel 1"); //Channel 2 Configuration NotificationChannel channel2 = new NotificationChannel(CHANNEL_2_ID, "channel 2",NotificationManager.IMPORTANCE_LOW); channel2.setDescription("Test Channel 2"); //Channel 3 Configuration NotificationChannel channel3 = new NotificationChannel(CHANNEL_3_ID, "channel 3",NotificationManager.IMPORTANCE_DEFAULT); channel3.setDescription("Test Channel 3"); //Channel 4 Configuration NotificationChannel channel4 = new NotificationChannel(CHANNEL_4_ID, "channel 4",NotificationManager.IMPORTANCE_HIGH); channel4.setDescription("Test Channel 4"); //Channel 5 Configuration NotificationChannel channel5 = new NotificationChannel(CHANNEL_5_ID, "channel 5",NotificationManager.IMPORTANCE_HIGH); channel5.setDescription("Test Channel 5"); NotificationManager manager = getSystemService(NotificationManager.class); manager.createNotificationChannel(channel1); manager.createNotificationChannel(channel2); manager.createNotificationChannel(channel3); manager.createNotificationChannel(channel4); manager.createNotificationChannel(channel5); } }
Example 19
Source File: MainActivity.java From SSLSocks with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. ViewPager mViewPager = findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); mViewPager.addOnPageChangeListener(onPageChangeListener); fabAdd = findViewById(R.id.fab); fabAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, KeyEditActivity.class); startActivityForResult(intent, KEY_EDIT_REQUEST); } }); // attempt extraction in activity, to make service start faster StunnelProcessManager.checkAndExtract(this); StunnelProcessManager.setupConfig(this); // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.notification_channel); String description = getString(R.string.notification_desc); int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance // or other notification behaviors after this NotificationManager notificationManager = getSystemService(NotificationManager.class); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); } } }
Example 20
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(Notification.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(temp.vibrate); template.setSound(temp.sound, generic_audio); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }