关于安卓Service通知栏提醒的问题

各位大侠好,我的Service能运行,输出也有,但就是通知栏提醒的部分无效,网上的代码都尝试了几遍,都不行,下面是代码:

NofyService.java

 public class NofyService extends Service {
    private final String TAG = "NofyService";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(this);
        PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        builder.setContentTitle("Bmob Test");
        builder.setContentText("message");
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentIntent(intent);//执行intent
        Notification notification = builder.getNotification();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        manager.notify(1,notification);
        Log.v(TAG, "onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Calendar ca = Calendar.getInstance();
        long[] vibrates = {0, 1000, 500, 1000};
        Notification notification = new Notification.Builder(getApplicationContext())
                .setContentTitle("事件提醒")
                .setContentText("有事件")
                .setVibrate(vibrates)
                .build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(1, notification);
        Log.v(TAG, "onStart");
        return START_STICKY;
    }

}

onCreate 和 onStart 的 Log 都有输出,就是没看到虚拟机的通知栏有消息,请问这是什么问题?

用真机测试一下看看有没有

我也遇到你一样的问题,同问

为什么 onCreate onStartCommand中有都有发通知的代码