public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("服务onStartCommand");
NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.icon);
mBuilder.setContentTitle("陈剑虹的播放器");
mBuilder.setContentText("享受美妙的音乐吧.");
Notification notification=mBuilder.build();
startForeground(startId, notification);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
stopForeground(true);
super.onDestroy();
}
让Android服务变为前台服务
最新推荐文章于 2024-07-25 19:04:18 发布