Android通知不适用于Android 6.0(棉花糖)
我正在安卓系统上实现本地通知,我的问题是它们没有出现在安卓6.0(三星S7)上。 我在寻找解决方案,但我找不到任何解决这个问题的方法。我在适当的res/drawable文件夹中有图标,我还定义了通知标题、文本、铃声(原始文件夹),但它没有显示。。。 这是我的代码:Android通知不适用于Android 6.0(棉花糖),android,notifications,android-notifications,android-6.0-marshmallow,Android,Notifications,Android Notifications,Android 6.0 Marshmallow,我正在安卓系统上实现本地通知,我的问题是它们没有出现在安卓6.0(三星S7)上。 我在寻找解决方案,但我找不到任何解决这个问题的方法。我在适当的res/drawable文件夹中有图标,我还定义了通知标题、文本、铃声(原始文件夹),但它没有显示。。。 这是我的代码: Context acontext = getApplicationContext(); PackageManager pm = acontext.getPackageManager(); Intent not
Context acontext = getApplicationContext();
PackageManager pm = acontext.getPackageManager();
Intent notificationIntent = pm.getLaunchIntentForPackage(acontext.getPackageName());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(acontext, 0, notificationIntent, 0);
int notification_icon = acontext.getResources().getIdentifier("icon", "drawable", acontext.getPackageName());
int notificationID = 0;
// Build notification
Notification noti = new Notification.Builder(acontext)
.setContentTitle("Title")
.setContentText("Incoming text")
.setSmallIcon(notification_icon)
.setContentIntent(pendingIntent)
.setLights(Color.RED, 1, 1)
.build();
NotificationManager notificationManager = (NotificationManager) acontext.getSystemService(Context.NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.sound = Uri.parse("android.resource://" + acontext.getPackageName() + "/raw/incoming");
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationID, noti);
还有其他人遇到过这个问题吗?任何帮助都将不胜感激。谢谢。必须启用Google Play服务才能在Android设备上接收推送通知。如果Google Play服务已启用,并且常规故障排除步骤尚未解决问题,则可能需要重置应用程序。要重置应用程序,请转到“设置”→ 应用程序→ 分页并点击清除数据 对于Android 6.0及更高版本,请确保该应用程序在优先模式下设置为优先应用程序
对于Android 6.0及更高版本,请检查应用程序是否在打瞌睡模式下静音。检查Android版本,相应地为>6.0和其他版本设置图标。对于6.0版本,我们需要白色背景图标
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
icon = R.mipmap.your_logo_for_Lolipop;
}else{
icon = R.drawable.your_logo_for_Kitkat ;
}
新通知中有一些更改。新的
NotificationCompat.Builder(此)
已被弃用,需要NotificationChannel
用于上面的android oreo。你可以试试这个解决方案
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(mContext.getApplicationContext(), "notify_001");
Intent ii = new Intent(mContext.getApplicationContext(), RootActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, ii, 0);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(verseurl);
bigText.setBigContentTitle("Title");
bigText.setSummaryText("Text in detail");
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);
mBuilder.setContentTitle("Your Title");
mBuilder.setContentText("Your text");
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
NotificationManager mNotificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("notify_001",
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
mNotificationManager.createNotificationChannel(channel);
}
mNotificationManager.notify(0, mBuilder.build());
在Android中显示通知涉及多个层次,请首先检查这是否适用于相同操作系统版本的其他设备。通常,这些问题是特定于设备而不是特定于操作系统的,还需要检查通知日志 如果问题是特定于设备的,则以下是方便的提示:
通知在较低版本上工作?是的,它在Android 5.0上工作。它是否在记录器中显示任何类型的消息?如果这是您的意思,则没有错误消息或警告,并且始终调用创建这些通知的方法,并且已创建通知对象。您找到解决方案了吗@TündeI已启用播放服务。此外,我还收到来自其他应用程序(如gmail或facebook…)的推送通知。只有我的应用程序的通知没有显示。非常感谢。这些新更改适用于android 8.0和更高版本,这些如何适用于android 6.0?