AndroidStudio中无法显示通知图标及其对应的文本和标题。
创始人
2024-08-21 08:00:11
0
  1. 确保已经声明了通知栏权限:



  1. 创建一个NotificationCompat.Builder对象:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!")
        .setAutoCancel(true)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
  1. 建立一个PendingIntent,在用户点击通知时启动活动:
Intent intent = new Intent(this, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

builder.setContentIntent(pendingIntent);
  1. 从NotificationManager中发送通知:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.notify(0, builder.build());
  1. 最后确认你的应用程序有通知栏权限,并重新启动你的应用程序以查看你的通知。

注意:如果你将setSmallIcon()设置为透明,会导致在某些设备和版本的Android上无法显示通知图标,请使用非透明的图标。

相关内容

热门资讯

一分钟辅助!wpk辅助,约局吧... 一分钟辅助!wpk辅助,约局吧德州可以透视吗,烘培教程(真的有挂)1、实时约局吧德州可以透视吗透视辅...
第9分钟辅助!pokemomo... 第9分钟辅助!pokemomo辅助软件,wepoker轻量版透视方法,大纲教程(有挂攻略)1)wep...
第9分钟辅助!wepokerp... 第9分钟辅助!wepokerplus辅助,pokemmo脚本辅助下载,妙招教程(真实有挂)该软件可以...
7分钟辅助!wepoker究竟... 7分钟辅助!wepoker究竟有没有透视,菠萝德普辅助器免费版在哪里,窍要教程(真实有挂)1、菠萝德...
六分钟辅助!hhpoker辅助... 六分钟辅助!hhpoker辅助软件下载,wpk辅助,妙招教程(有挂秘籍)运hhpoker辅助软件下载...
五分钟辅助!来玩app破解,a... 五分钟辅助!来玩app破解,aapoker ai插件,举措教程(有挂讲解)1、aapoker ai插...
8分钟辅助!菠萝辅助器免费版的... 8分钟辅助!菠萝辅助器免费版的特点,sohoo开挂辅助,讲义教程(有挂秘笈)菠萝辅助器免费版的特点透...
第三分钟辅助!wepoker有... 第三分钟辅助!wepoker有没有挂,wepoker私人局透视,手筋教程(有挂方略)1、操作简单,无...
第九分钟辅助!aapoker透... 第九分钟辅助!aapoker透视插件,菠萝辅助器免费版的特点,绝活教程(有挂技术)1、完成菠萝辅助器...
6分钟辅助!德州透视是真的假的... 6分钟辅助!德州透视是真的假的,wepoker辅助器是真的吗,举措教程(有挂分享)1、wepoker...