要使用Android通知,您可以按照以下步骤操作:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My Notification") .setContentText("This is a notification message");
Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, builder.build());
以上代码中,notificationId是一个用于区分不同通知的整数值。
此外,您还可以设置其他属性,比如声音、震动、大文本样式、进度等。
希望这可以帮助到您。