我不能让这个简单的通知出现,我一直在寻找教程,他们都提供相同的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("hgfyjdgh", "Mychannel", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
public void click(View v) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "id");
builder.setSmallIcon(R.drawable.img)
.setContentTitle("Uber Driver")
.setContentText("أنت الان متصل")
.setPriority(NotificationCompat.PRIORITY_HIGH);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(23, builder.build());
Toast.makeText(this, "done", Toast.LENGTH_LONG).show();
}
您需要在qazxsw po创建时以及通知时拥有相同的频道
创建通知通道名称
NotificationChannel
注册它
String NOTIFICATION_CHANNEL_ID = "com.appname.example";
通知它
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "MyChannelName", NotificationManager.IMPORTANCE_DEFAULT);