here is my full code
Start notification work well in Service, but when i change service to IntentService, the notification doesn't show, here is my service:
public class MyIntentService extends IntentService {
public MyIntentService() {
super("MyIntentService");
}
Context ctx;
String channelId;
@Override
protected void onHandleIntent(Intent intent) {
ctx = getApplicationContext();
channelId = getPackageName() + " Channel";
createNotificationChannel();
startForeground(1, getNotification());
}
Notification getNotification() {
return new NotificationCompat.Builder(ctx, channelId)
.setContentTitle("Title")
.setContentText("Content")
.setSmallIcon(R.drawable.ic_android_black_24dp)
.build();
}
private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String name = channelId + " Name";
String description = channelId + " Desc";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(channelId, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
}
I start service with following code:
startService(new Intent(this, MyIntentService.class))