I' writing a code to show a notification channel in my application, in android studio. What I'm dealing with is that the android studio does not show me the notification bar in the application. What should I do to fix this issue?
package com.example.notification_example;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
NotificationManager notification;
Button btn;
String ChannelID = "ChannelID";
String ChannelName = "ChannelName";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button);
notification = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(ChannelID,
ChannelName,
NotificationManager.IMPORTANCE_DEFAULT);
notification.createNotificationChannel(notificationChannel);
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this, ChannelID);
builder.setSmallIcon(R.drawable.hand_notification)
.setContentTitle("Updates").setContentText("Updates Are ready to install");
notification.notify(1, builder.build());
}
}
});
}
}
When I click the button, the notification bar will not be indicated.