无论我尝试什么
老实说,我开始相信标题中报道的问题是在商店中发布的新Android API的问题。我尝试在清单中设置Android:lainingMode =“ singletask”,以下是我的构建和显示通知的代码。我进行了调整和调整,但是每当按下通知时,应用程序都会重新启动。
//其他信息: Android Studio:2021.3 模拟:像素4 XL API 30 SDK:Android 11 还在物理设备上测试:true 缓存无效:true
//代码
private void showNotification(int notificationID, String title, String message, String channel_id, String channelName, String channelDescription, int notifIcon)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(channel_id, channelName, importance);
mChannel.setDescription(channelDescription);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.enableLights(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mChannel.setShowBadge(false);
mChannel.setLightColor(Color.RED);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channel_id).setSmallIcon(notifIcon).setContentTitle(title).setContentText(message);
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
builder.setOngoing(true);//s that it can't just be swiped away!
//
notificationManager.notify(notificationID, builder.build());
}
I am honestly starting to believe the issue reported in the title is an issue with the new Android API required to publish on the store. I have tried setting android:launchMode="singleTask" in the manifest, and below is my code to build and show the notification. I have tweaked and tweaked but whenever the notification is pressed, the app restarts.
//other info:
Android Studio: 2021.3
Emulated: Pixel 4 XL API 30
SDK: Android 11
Also tested on physical device: true
Cache invalidated: true
//CODE
private void showNotification(int notificationID, String title, String message, String channel_id, String channelName, String channelDescription, int notifIcon)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(channel_id, channelName, importance);
mChannel.setDescription(channelDescription);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.enableLights(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mChannel.setShowBadge(false);
mChannel.setLightColor(Color.RED);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channel_id).setSmallIcon(notifIcon).setContentTitle(title).setContentText(message);
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
builder.setOngoing(true);//s that it can't just be swiped away!
//
notificationManager.notify(notificationID, builder.build());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论