use of android.app.NotificationChannel in project NewPipe by TeamNewPipe.
the class App method initNotificationChannel.
public void initNotificationChannel() {
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
return;
}
final String id = getString(R.string.notification_channel_id);
final CharSequence name = getString(R.string.notification_channel_name);
final String description = getString(R.string.notification_channel_description);
// Keep this below DEFAULT to avoid making noise on every notification update
final int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
}
use of android.app.NotificationChannel in project browser by scoute-dich.
the class NotificationUnit method getHBuilder.
public static NotificationCompat.Builder getHBuilder(Context context) {
NotificationCompat.Builder builder;
final BroadcastReceiver stopNotificationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Intent toHolderService = new Intent(context, HolderService.class);
IntentUnit.setClear(false);
context.stopService(toHolderService);
BrowserContainer.clear();
}
};
IntentFilter intentFilter = new IntentFilter("stopNotification");
context.registerReceiver(stopNotificationReceiver, intentFilter);
Intent stopNotification = new Intent("stopNotification");
PendingIntent stopNotificationPI = PendingIntent.getBroadcast(context, 0, stopNotification, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Action action_UN = new NotificationCompat.Action.Builder(R.drawable.icon_earth, context.getString(R.string.toast_closeNotification), stopNotificationPI).build();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// The id of the channel.
String CHANNEL_ID = "browser_not";
// The user-visible name of the channel.
CharSequence name = context.getString(R.string.app_name);
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(mChannel);
builder = new NotificationCompat.Builder(context, CHANNEL_ID);
} else {
builder = new NotificationCompat.Builder(context);
}
builder.setCategory(Notification.CATEGORY_MESSAGE);
builder.setSmallIcon(R.drawable.ic_notification_ninja);
builder.setContentTitle(context.getString(R.string.notification_content_holderTitle));
builder.setContentText(context.getString(R.string.notification_content_holder));
builder.setColor(ContextCompat.getColor(context, R.color.colorAccent));
builder.setAutoCancel(true);
builder.setPriority(Notification.PRIORITY_HIGH);
builder.setVibrate(new long[0]);
builder.addAction(action_UN);
Intent toActivity = new Intent(context, BrowserActivity.class);
PendingIntent pin = PendingIntent.getActivity(context, 0, toActivity, 0);
builder.setContentIntent(pin);
return builder;
}
use of android.app.NotificationChannel in project Tusky by tuskyapp.
the class NotificationHelper method areNotificationsEnabled.
public static boolean areNotificationsEnabled(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// on Android >= O, notifications are enabled, if at least one channel is enabled
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// noinspection ConstantConditions
if (notificationManager.areNotificationsEnabled()) {
for (NotificationChannel channel : notificationManager.getNotificationChannels()) {
if (channel.getImportance() > NotificationManager.IMPORTANCE_NONE) {
Log.d(TAG, "NotificationsEnabled");
return true;
}
}
}
Log.d(TAG, "NotificationsDisabled");
return false;
} else {
// on Android < O, notifications are enabled, if at least one account has notification enabled
return TuskyApplication.getInstance(context).getServiceLocator().get(AccountManager.class).areNotificationsEnabled();
}
}
use of android.app.NotificationChannel in project android-play-location by googlesamples.
the class LocationUpdatesService method onCreate.
@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);
}
}
use of android.app.NotificationChannel in project android_packages_apps_Settings by DirtyUnicorns.
the class BluetoothPermissionRequest method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
String action = intent.getAction();
if (DEBUG)
Log.d(TAG, "onReceive" + action);
if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
// skip the notification for managed profiles.
if (um.isManagedProfile()) {
if (DEBUG)
Log.d(TAG, "Blocking notification for managed profile.");
return;
}
// convert broadcast intent into activity intent (same action string)
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION);
mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
if (DEBUG)
Log.d(TAG, "onReceive request type: " + mRequestType + " return " + mReturnPackage + "," + mReturnClass);
// dialog or notification.
if (checkUserChoice()) {
return;
}
Intent connectionAccessIntent = new Intent(action);
connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
// We use the FLAG_ACTIVITY_MULTIPLE_TASK since we can have multiple concurrent access
// requests.
connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
// This is needed to create two pending intents to the same activity. The value is not
// used in the activity.
connectionAccessIntent.setType(Integer.toString(mRequestType));
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
String deviceName = mDevice != null ? mDevice.getName() : null;
String title = null;
String message = null;
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powerManager.isScreenOn() && LocalBluetoothPreferences.shouldShowDialogInForeground(context, deviceAddress, deviceName)) {
context.startActivity(connectionAccessIntent);
} else {
// Put up a notification that leads to the dialog
// Create an intent triggered by clicking on the
// "Clear All Notifications" button
Intent deleteIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO);
deleteIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
String deviceAlias = Utils.createRemoteName(context, mDevice);
switch(mRequestType) {
case BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS:
title = context.getString(R.string.bluetooth_phonebook_request);
message = context.getString(R.string.bluetooth_pb_acceptance_dialog_text, deviceAlias, deviceAlias);
break;
case BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS:
title = context.getString(R.string.bluetooth_map_request);
message = context.getString(R.string.bluetooth_map_acceptance_dialog_text, deviceAlias, deviceAlias);
break;
case BluetoothDevice.REQUEST_TYPE_SIM_ACCESS:
title = context.getString(R.string.bluetooth_sap_request);
message = context.getString(R.string.bluetooth_sap_acceptance_dialog_text, deviceAlias, deviceAlias);
break;
default:
title = context.getString(R.string.bluetooth_connection_permission_request);
message = context.getString(R.string.bluetooth_connection_dialog_text, deviceAlias, deviceAlias);
break;
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationChannel == null) {
mNotificationChannel = new NotificationChannel(BLUETOOTH_NOTIFICATION_CHANNEL, context.getString(R.string.bluetooth), NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(mNotificationChannel);
}
Notification notification = new Notification.Builder(context, BLUETOOTH_NOTIFICATION_CHANNEL).setContentTitle(title).setTicker(message).setContentText(message).setSmallIcon(android.R.drawable.stat_sys_data_bluetooth).setAutoCancel(true).setPriority(Notification.PRIORITY_MAX).setOnlyAlertOnce(false).setDefaults(Notification.DEFAULT_ALL).setContentIntent(PendingIntent.getActivity(context, 0, connectionAccessIntent, 0)).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setLocalOnly(true).build();
// Cannot be set with the builder.
notification.flags |= Notification.FLAG_NO_CLEAR;
notificationManager.notify(getNotificationTag(mRequestType), NOTIFICATION_ID, notification);
}
} else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
// Remove the notification
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
manager.cancel(getNotificationTag(mRequestType), NOTIFICATION_ID);
}
}
Aggregations