Android 8.1.0输入通知通知未在启动器/主页上显示



我对Android 8.1.0应用程序有疑问。当应用程序在启动器页面或主页中时,未显示传入通知通知。如果该应用程序在其他页面中,则来电将将页面更改为电话页面。请帮助。

如果您的targetsdkversion 27中的应用程序在上面的Android 8.0中显示通知,则需要在设备上方显示通知ID才能显示通知。我提供了简单的通知代码以在Android 8.0设备中显示通知。

制作一种创建频道的方法。

public void createChannels(String channel1) {
    // create android channel
    mChannleId =channel1;// show channel mChannleName.
    NotificationChannel androidChannel = new NotificationChannel(channel1,
            mChannleName, NotificationManager.IMPORTANCE_DEFAULT);
    //mChannel_Id=channel1;
    // Sets whether notifications posted to this channel should display notification lights
    androidChannel.enableLights(true);
    androidChannel.setDescription(mDescription);
    androidChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
    // Sets whether notification posted to this channel should vibrate.
    androidChannel.enableVibration(true);
    // Sets the notification light color for notifications posted to this channel
    androidChannel.setLightColor(Color.GREEN);
    // Sets whether notifications posted to this channel appear on the lockscreen or not
    androidChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    androidChannel.setShowBadge(true);
    getManager().createNotificationChannel(androidChannel);
    Toast.makeText(getApplicationContext(),"Channel created",Toast.LENGTH_SHORT).show();
}

然后在创建通知之后

 public Notification.Builder createNotification(String message)
{
    Intent resultIntent = new Intent(this, ResultActivity.class);
    resultIntent.putExtra("message",message);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ResultActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    return new Notification.Builder(getApplicationContext(),mChannel_Id)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(mChannel_Id)
            .setContentText(message)
            //.setGroup(group)
            .setChannelId(mChannel_Id)
            .setContentIntent(resultPendingIntent);
}

更多信息在下面的链接下得到指导。 - 有关使用channel_id和group创建通知类型的更多信息。--https://developer.android.com/guide/topics/ui/notifiers/notifierations.html?

-https://code.tutsplus.com/tutorials/android-o-how-how-to-use-notification-notification-channels-CMS-28616

相关内容

  • 没有找到相关文章

最新更新