要解决Android 13中通知操作按钮无法正常工作的问题,可以尝试以下解决方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "channel_id";
NotificationChannel channel = new NotificationChannel(channelId, "Channel Name", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Title")
.setContentText("Content")
.addAction(R.drawable.ic_action, "Action", pendingIntent);
notificationManager.notify(notificationId, builder.build());
} else {
// Android 7及更低版本的通知创建代码
}
Intent intent = new Intent(this, MyBroadcastReceiver.class);
intent.setAction("ACTION");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Title")
.setContentText("Content")
.addAction(R.drawable.ic_action, "Action", pendingIntent);
以上是一些可能的解决方法,根据具体情况可能会有所不同。如若问题仍然存在,建议查看Android开发者官方文档、参考相关讨论和问题报告,以获取更多帮助。