Skip to main content

 Android Notification show 



public static void shownotification(Context context, int id, String title, String Content, Intent intent)
{
PendingIntent pendingIntent=null;
if (intent!=null)
{
pendingIntent=PendingIntent.getActivities(context,id, new Intent[]{intent},PendingIntent.FLAG_UPDATE_CURRENT);
String NOTIIFCATION_CHANNEL_ID="UClone android";
NotificationManager notificationManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
{
NotificationChannel notificationChannel=new NotificationChannel(NOTIIFCATION_CHANNEL_ID,"",NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription("");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0,1000,500,1000});
notificationChannel.enableVibration(true);

notificationManager.createNotificationChannel(notificationChannel);

}
NotificationCompat.Builder builder=new NotificationCompat.Builder(context,NOTIIFCATION_CHANNEL_ID);
builder.setContentTitle(title);
builder.setContentText(Content);
builder.setAutoCancel(false);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setDefaults(Notification.DEFAULT_VIBRATE);
builder.setSmallIcon(R.drawable.car);
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.drawable.car_display));

if (pendingIntent!=null)
{
builder.setContentIntent(pendingIntent);
}
Notification notification= builder.build();
notificationManager.notify(id,notification);

}


}

Example: 2

private void addNotification() {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.messageicon) //set icon for notification
.setContentTitle("Notifications Example") //set title of notification
.setContentText("This is a notification message")//this is notification message
.setAutoCancel(true) // makes auto cancel of notification
.setPriority(NotificationCompat.PRIORITY_DEFAULT); //set priority of notification


Intent notificationIntent = new Intent(this, NotificationView.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//notification message will get at NotificationView
notificationIntent.putExtra("message", "This is a notification message");

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);

// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}

Comments

Popular posts from this blog

 var val  deference in kotlin  fun main () { var Android_Programing_language : String = "java" println ( "android official programing language: " + Android_Programing_language ) Android_Programing_language = "Kotline" println ( "2019 google announced android official programing language: " + Android_Programing_language ) val Android_MultiPlatform_language : String = "Dart" println ( "multiple device run : " + Android_MultiPlatform_language ) /* Android_MultiPlatform_language="" /* note: var--------------valu changable note: val--------------valu not changable (final) */ */ }
 Firebase Cloud Messaging With  push notification with Image  public class ImageDownload extends AsyncTask < String , Void , Bitmap >{ @Override protected Bitmap doInBackground ( String ... strings ) { InputStream inputStream ; try { URL url = new URL( strings [ 0 ]) ; try { HttpURLConnection connection = ( HttpURLConnection ) url .openConnection() ; connection .connect() ; inputStream = connection .getInputStream() ; return BitmapFactory . decodeStream ( inputStream ) ; } catch ( IOException e ) { e .printStackTrace() ; } } catch ( MalformedURLException e ) { e .printStackTrace() ; } return null; } @Override protected void onPostExecute ( Bitmap bitmap ) { ShowNotification( bitmap ) ; } }
  Kotlin Function function means use big problems divided by submodule and easily problems solved.   It makes reusability of code and makes the program more manageable There are two types of functions: Standard library function User-defined function Standard Library Function Kotlin Standard library function is built-in library functions import java.time.LocalDateTime fun main (args: Array < String >) { val current = LocalDateTime.now() println( "Current Date and Time is: $current " ) } User-defined Function A user-defined is created by the user. User-defined function takes the parameter(s), perform an action and return the result of that action as a value. fun  main(args: Array<String>){       sum()       print( "code after sum" )   }   fun  sum(){       var num1 = 5        var...