Tools - Notification

//Generate Alert Feature


Notification.Builder mBuilder = new Notification.Builder(MainActivity.this);
mBuilder.setSmallIcon(R.drawable.appicon);
mBuilder.setContentTitle("You're Title");
mBuilder.setContentText("You're Text");
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int onx = 1;
notificationManager.notify(onx, mBuilder.build());


//Run activity and create alert notification

Notification.Builder mBuilder = new Notification.Builder(MainActivity.this);
mBuilder.setSmallIcon(R.drawable.appicon);
mBuilder.setContentTitle("You're Title");
mBuilder.setContentText("You're Text");
mBuilder.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(
getApplicationContext(), SwwActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
notificationIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pendingIntent).setAutoCancel(true);
mBuilder.setOngoing(true);
int onx = 2;
notificationManager.notify(onx, mBuilder.build());


//Generate in-progress Notification
Notification.Builder mBuilder = new Notification.Builder(MainActivity.this);
mBuilder.setSmallIcon(R.drawable.appicon);
mBuilder.setContentTitle("You're Title");
mBuilder.setContentText("You're Text");
mBuilder.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(
getApplicationContext(), SwwActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
notificationIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pendingIntent).setAutoCancel(false);
mBuilder.setOngoing(true);
int onx = 3;
notificationManager.notify(onx, mBuilder.build());



//Generate custome notification

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
Notification.Builder mBuilder = new Notification.Builder(MainActivity.this);
mBuilder.setSmallIcon(R.drawable.appicon);
mBuilder.setContent(contentView);
mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(getApplicationContext(),
MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pendingIntent).setAutoCancel(false);
notificationManager.notify(4, mBuilder.build());


//Generate custome image notification
Notification.Builder mBuilder = new Notification.Builder(MainActivity .this); mBuilder.setSmallIcon(R.drawable.icon_name); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon_name); mBuilder.setLargeIcon(bm); Bitmap mm = BitmapFactory.decodeResource(getResources(), R.drawable.icon_name); mBuilder.setStyle(new Notification.BigPictureStyle()          .bigPicture(mm)); mBuilder.setContentTitle("You're Title"); mBuilder.setContentText("You're Text"); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class ); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK); mBuilder.setContentIntent(pendingIntent).setAutoCancel(true); notificationManager.notify(1, mBuilder.build());



//Clear notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(*ID*);

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key