use of android.app.NotificationChannel in project haven by guardianproject.
the class MonitorService method onCreate.
/**
* Called on service creation, sends a notification
*/
@Override
public void onCreate() {
sInstance = this;
mApp = (HavenApp) getApplication();
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mPrefs = new PreferenceManager(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
mChannel.setDescription(channelDescription);
mChannel.setLightColor(Color.RED);
mChannel.setImportance(NotificationManager.IMPORTANCE_MIN);
manager.createNotificationChannel(mChannel);
}
startSensors();
showNotification();
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
wakeLock.acquire();
}
use of android.app.NotificationChannel in project mixpanel-android by mixpanel.
the class GCMReceiver method makeNotificationSDK26OrHigher.
@SuppressLint("NewApi")
@TargetApi(26)
protected Notification makeNotificationSDK26OrHigher(Context context, PendingIntent intent, NotificationData notificationData) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = MPConfig.getInstance(context).getNotificationChannelId();
String channelName = MPConfig.getInstance(context).getNotificationChannelName();
int importance = MPConfig.getInstance(context).getNotificationChannelImportance();
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
int notificationDefaults = MPConfig.getInstance(context).getNotificationDefaults();
if (notificationDefaults == Notification.DEFAULT_VIBRATE || notificationDefaults == Notification.DEFAULT_ALL) {
channel.enableVibration(true);
}
if (notificationDefaults == Notification.DEFAULT_LIGHTS || notificationDefaults == Notification.DEFAULT_ALL) {
channel.enableLights(true);
channel.setLightColor(Color.WHITE);
}
mNotificationManager.createNotificationChannel(channel);
final Notification.Builder builder = new Notification.Builder(context).setTicker(notificationData.message).setWhen(System.currentTimeMillis()).setContentTitle(notificationData.title).setContentText(notificationData.message).setContentIntent(intent).setStyle(new Notification.BigTextStyle().bigText(notificationData.message)).setChannelId(channelId);
if (notificationData.whiteIcon != NotificationData.NOT_SET) {
builder.setSmallIcon(notificationData.whiteIcon);
} else {
builder.setSmallIcon(notificationData.icon);
}
if (notificationData.largeIcon != NotificationData.NOT_SET) {
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), notificationData.largeIcon));
}
if (notificationData.color != NotificationData.NOT_SET) {
builder.setColor(notificationData.color);
}
final Notification n = builder.build();
n.flags |= Notification.FLAG_AUTO_CANCEL;
return n;
}
use of android.app.NotificationChannel in project Android-Group-39 by Area51TrainingCenter.
the class MyAlarmService method showNotification.
private void showNotification() {
final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL_ALARM_ID, getString(R.string.notification_channel_alarm), NotificationManager.IMPORTANCE_HIGH));
}
notificationManager.notify(NOTIFICATION_ID, buildNotification());
}
use of android.app.NotificationChannel in project Android-NotesApp by HelloPraveenIO.
the class MainActivity method onCreate.
@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
SpannableStringBuilder SS = new SpannableStringBuilder("Notes");
SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
if (getSupportActionBar() != null)
getSupportActionBar().setTitle(SS);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
FloatingActionButton fab = findViewById(R.id.fab);
CoordinatorLayout sv = findViewById(R.id.fabView);
populateData();
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, NoteActivity.class);
startActivity(i);
finish();
}
});
boolean fromNew;
boolean fromEdit;
boolean fromDelete;
boolean fromRestore;
if (this.getIntent().getExtras() != null && this.getIntent().getExtras().containsKey("note")) {
fromNew = getIntent().getExtras().getBoolean("new");
fromEdit = getIntent().getExtras().getBoolean("edit");
fromDelete = getIntent().getExtras().getBoolean("delete");
fromRestore = getIntent().getExtras().getBoolean("restore");
if (fromNew)
Snackbar.make(sv, "Note added successfully!", Snackbar.LENGTH_SHORT).show();
if (fromEdit)
Snackbar.make(sv, "Note edited successfully!", Snackbar.LENGTH_SHORT).show();
if (fromDelete)
Snackbar.make(sv, "Note deleted successfully!", Snackbar.LENGTH_SHORT).show();
if (fromRestore)
Snackbar.make(sv, "Note restored successfully!", Snackbar.LENGTH_SHORT).show();
InterstitialAd interstitialAd = new InterstitialAd(MainActivity.this);
interstitialAd.setAdUnitId("ca-app-pub-6275597090094912/5536611682");
interstitialAd.loadAd(new AdRequest.Builder().build());
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
boolean shortcut = preferences.getBoolean("shortcut", true);
if (!shortcut) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int notificationId = 1;
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "NOTES_ADD";
String channelName = "Notes Shortcuts";
@SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(channelId, channelName, 3);
if (notificationManager != null) {
mChannel.setSound(null, null);
notificationManager.createNotificationChannel(mChannel);
}
Intent intent = new Intent(this, NoteActivity.class);
intent.putExtra("IS_FROM_NOTIFICATION", true);
@SuppressLint("WrongConstant") PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, NotificationManager.IMPORTANCE_LOW);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), channelId);
builder.setContentTitle("Tap to add a note");
builder.setContentText("Note something productive today.");
builder.setContentIntent(pendingIntent);
builder.setTicker("Add Notes");
builder.setChannelId(channelId);
builder.setOngoing(true);
builder.setColor(getResources().getColor(R.color.colorPrimary));
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.notification_white);
builder.setPriority(NotificationManager.IMPORTANCE_LOW);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
if (notificationManager != null)
notificationManager.notify(notificationId, builder.build());
} else {
Intent intent = new Intent(this, NoteActivity.class);
intent.putExtra("IS_FROM_NOTIFICATION", true);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentTitle("Tap to add a note");
builder.setContentText("Note something productive today.");
builder.setContentIntent(pendingIntent);
builder.setTicker("Add Notes");
builder.setOngoing(true);
builder.setAutoCancel(true);
builder.setColor(getResources().getColor(R.color.colorPrimary));
builder.setSmallIcon(R.drawable.notification_white);
builder.setPriority(Notification.PRIORITY_MAX);
Notification notification = builder.build();
NotificationManager notificationManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManger != null)
notificationManger.notify(1, notification);
}
} else {
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (nMgr != null)
nMgr.cancelAll();
}
}
use of android.app.NotificationChannel in project Android-NotesApp by HelloPraveenIO.
the class NoteActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
interstitialAd = new InterstitialAd(NoteActivity.this);
interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
interstitialAd.loadAd(new AdRequest.Builder().build());
intent2 = new Intent(NoteActivity.this, MainActivity.class);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(NoteActivity.this);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
SpannableStringBuilder SS = new SpannableStringBuilder("Add Note");
SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(SS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
boolean b = preferences.getBoolean("shortcut", true);
premium = preferences.getInt("premium", 0);
if (!b) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int notificationId = 1;
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "TN_1";
String channelName = "Type Note Shortcuts";
@SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(channelId, channelName, 3);
if (notificationManager != null) {
mChannel.setSound(null, null);
notificationManager.createNotificationChannel(mChannel);
}
Intent intent = new Intent(this, NoteActivity.class);
intent.putExtra("IS_FROM_NOTIFICATION", true);
@SuppressLint("WrongConstant") PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, NotificationManager.IMPORTANCE_LOW);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setContentTitle("Tap to add a note");
builder.setContentText("Note something productive today.");
builder.setContentIntent(pendingIntent);
builder.setTicker("Add Notes");
builder.setChannelId(channelId);
builder.setColor(getResources().getColor(R.color.colorPrimary));
builder.setOngoing(true);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.notification_white);
builder.setPriority(Notification.PRIORITY_MAX);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
if (notificationManager != null)
notificationManager.notify(notificationId, builder.build());
} else {
Intent intent = new Intent(this, NoteActivity.class);
intent.putExtra("IS_FROM_NOTIFICATION", true);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentTitle("Tap to add a note");
builder.setContentText("Note something productive today.");
builder.setContentIntent(pendingIntent);
builder.setTicker("Add Notes");
builder.setOngoing(true);
builder.setColor(getResources().getColor(R.color.colorPrimary));
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.notification_white);
builder.setPriority(Notification.PRIORITY_MAX);
Notification notification = builder.build();
NotificationManager notificationManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManger != null)
notificationManger.notify(1, notification);
}
}
FloatingActionButton fab = findViewById(R.id.add_fab);
text = findViewById(R.id.add_text);
title = findViewById(R.id.add_title);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(@NonNull View v) {
String note = text.getText().toString();
Title = title.getText().toString();
if (note.length() > 0) {
Calendar c = Calendar.getInstance();
@SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("HH:mm dd/MM/yyyy");
String formattedDate = df.format(c.getTime());
DatabaseHandler db = new DatabaseHandler(NoteActivity.this);
db.addNote(new Note(note, formattedDate, imp, Title));
intent2.putExtra("note", true);
intent2.putExtra("new", true);
if (interstitialAd.isLoaded() && premium != 1) {
interstitialAd.show();
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
startActivity(intent2);
finish();
}
});
} else {
startActivity(intent2);
finish();
}
} else {
Snackbar.make(v, "Note is empty!", Snackbar.LENGTH_SHORT).show();
}
}
});
}
Aggregations