让Android服务变为前台服务

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笔记)