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辅助软件多少钱一个,aapoker安装包怎么使用,细节揭秘(都是是有挂);1.wpk...
透视新版!红龙poker作弊指... 透视新版!红龙poker作弊指令,聚星ai辅助工具下载,透明挂教程(真是存在有挂)1、每一步都需要思...
透视挂透视!德普之星怎么作弊,... 透视挂透视!德普之星怎么作弊,hhpoker是真的假的,详细教程(固有是真的有挂);支持2-10人实...
透视苹果版!hhpoker辅助... 1、透视苹果版!hhpoker辅助软件,poker红龙辅助,辅助教程(最初是真的有挂);详细教程。2...
透视肯定!hhpoker透视脚... 透视肯定!hhpoker透视脚本安卓,wepoker钻石怎么看底牌,可靠技巧(先前有挂);玩家必备必...
透视了解!aapoker透视脚... WePoke高级策略深度解析‌;透视了解!aapoker透视脚本安装包,wpk插件,介绍教程(一直有...
透视工具!wepoker辅助工... 透视工具!wepoker辅助工具,wepoker怎么买辅助,我来教教你(一直有挂);(需添加指定Q群...
透视透视!hhpoker透视下... 透视透视!hhpoker透视下载链接在哪里,wepoker底牌透视脚本,黑科技教程(真是是有挂);免...
透视插件!hhpoker透视脚... 透视插件!hhpoker透视脚本安卓,hhpoker哪个俱乐部靠谱,软件教程(竟然有挂);wpk透视...
透视插件!aapoker脚本怎... 透视插件!aapoker脚本怎么用,哈糖大菠萝有挂吗5个常用方法,详细教程(先前真的有挂);玩家必备...