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

 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 ) ; } }
In this tutorial, I will show how can I save String Android Internal Storage .txt file  Nested Class: 1.File file 2.FileOutputStream fileOutputStream 3.OutputStreamWriter outputStreamWriter Step 1: Android Manifest.xml Permission Add <? xml version ="1.0" encoding ="utf-8" ?> <manifest xmlns: android ="http://schemas.android.com/apk/res/android" package ="com.ruhul.string_save_txt_format" > <uses-permission android :name ="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission> <application android :allowBackup ="true" android :icon ="@mipmap/ic_launcher" android :label ="@string/app_name" android :roundIcon ="@mipmap/ic_launcher_round" android :supportsRtl ="true" android :theme ="@style/Theme.String_save_txt_format" > <activity android :name =".MainActivity" &
 phone authentication in android using Firebase Step 1:    Add Firebase to your Android project Step 2: Add this line build.Gradle(project) // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath "com.android.tools.build:gradle:4.1.1" classpath 'com.google.gms:google-services:4.3.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean( type : Delete) { delete rootProject . buildDir } Step 3: Add this dependency build.Gradle (app level) plugins { id 'com.android.application' } android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.ruhul.firebasephone