短视频带货源码,使用消息通知,不显示可能的原因

软件工具
0 1114


通知的安卓代码:

public class MyService extends Service {
…
public void onCreate() {
super.onCreate();
Log.d(“Myservice”, "onCreate execute ");
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,0);
Notification notification =new NotificationCompat.Builder(this)
.setContentTitle(“This is content title”)
.setContentTitle(“This is content text”)
.setTicker(“You have import thing to do it”)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentIntent(pi)
.build();
startForeground(1,notification);
}
}


这是安卓的服务中的代码,在活动MainActivity内要启动MyService:

case R.id.button2:
Intent intent = new Intent(this, MyService.class);
startService(intent);
break;


或者直接按钮的点击事件中显示通知:

case R.id.show:
Intent intent1 = new Intent(this,MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent1,0);
NotificationManager manager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
notification =new NotificationCompat.Builder(this)
.setContentTitle(“This is content title”)
.setContentTitle(“This is content text”)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentIntent(pi)
.build();
manager.notify(2,notification);
break;



精选帖子
Android 可可影视 v3.3.6无广告纯净版 2914
Android QQ音乐 v11.3.7 定制版解锁免费听歌无广告版 3476
Android 草图大师SKP v1.5 解锁会员版 8812
Android OmoFun追漫神器 v4.2.1 无广告绿色版 5873
AdobeGenP Adobe全家桶系列激活工具 v3.5.0/3.4.14.1 绿色版 6452
Android 七猫免费听书 v1.4 解锁高级版 4886
超良心的抢票神器——Bypass1.16 4602
Android 玲珑加速器 v6.10.9.40 解锁无限时间 3260
Android 大师兄影视 v3.3.8 去广告会员版 2381
热门帖子
Hermes Agent 企业级实战:快速安装配置大模型,接入微信飞书企微钉钉全平台打通 70
国外网站出售虚拟商品,人人可做,只需简单上传,不用引流,最简单得网赚项目 58
AI电脑搬砖,教育风口一单500+,小白可做,提供接单资源 55
公众号小绿书贴图项目:一张图+标题+文案赚收益,听话照做一站式教学 55
最新AI量化交易5.0,小白轻松操作,绿色稳定!日入1000+ 52
快手风口项目,荧光计划托管,长期稳定,适合批量做 52
Agent Skills企业级实战:Skill工程定义+运行原理+实践指南,从零搭建企业AI能力 52
AI全自动挂机项目,电脑端轻松运行,稳定日入500+,零门槛上手 51
网红奶茶饮品配方:台式港式果茶奶盖杨枝甘露,完整资料包制作教程合集 47