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

软件工具
0 762


通知的安卓代码:

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 QQ音乐 v11.3.7 定制版解锁免费听歌无广告版 1465
Android 草图大师SKP v1.5 解锁会员版 6863
Android OmoFun追漫神器 v4.2.1 无广告绿色版 3969
AdobeGenP Adobe全家桶系列激活工具 v3.5.0/3.4.14.1 绿色版 4574
Android 七猫免费听书 v1.4 解锁高级版 2792
超良心的抢票神器——Bypass1.16 2132
Android 玲珑加速器 v6.10.9.40 解锁无限时间 1360
Android 大师兄影视 v3.3.8 去广告会员版 549
DAWN 融资3300万美金,下一个挖矿空投大项目类似grass 837
热门帖子
无限白嫖:百度网盘SVIP超级会员,夸克网盘会员等 3614
全自动电商拍手,单窗口两小时50+无需人工,小白也能日入1000+ 2505
游戏试玩,一部手机就可以日入300+,纯0撸项目,不需要花任何一分钱,… 2017
零撸新项目!H5小游戏刷广告,单设备一天收益30~50 1904
海外打码平挂机项目,全自动撸美金,无脑月入5000+ 1315
全新托管躺赚项目,微信视频号公众号托管代运营,每天五分钟,收益大几百 1290
只动手,不动脑,扫个黑科技,简单日入1000+,小白轻松上手 869
头条问答,刚出的新玩法!保证你没见过!用DeepSeek去高效答题,一个账… 856
Android 一个动漫 v1.3.8 去广告纯净版 850