問題描述
android startForegroundService ,調用了startForeground還是報同樣錯
相關代碼
// 請把代碼文本粘貼到下方(請勿用圖檔代替代碼)
if (Build.VERSION.SDK_INT >= 26) {
this.startForegroundService(new Intent(this, TestService.class));
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel Channel = new NotificationChannel("bxforeground", "啦啦啦", NotificationManager.IMPORTANCE_HIGH);
Channel.enableLights(true);//設定提示燈
Channel.setLightColor(Color.RED);//設定提示燈顔色
Channel.setShowBadge(true);//顯示logo
Channel.setDescription("啦啦啦");//設定描述
Channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); //設定鎖屏可見 VISIBILITY_PUBLIC=可見
manager.createNotificationChannel(Channel);
Notification notification = new Notification.Builder(this)
.setChannelId("bxforeground")
.setContentTitle("啦啦啦")
.setContentText("啦啦啦")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.build();
startForeground(102, notification);
} else {
this.startService(new Intent(JobWakeService.this, TestService.class));
}
你期待的結果是什麼?實際看到的錯誤資訊又是什麼?
