Android O 오류 해결 Context.startForegroundService()가 Service.startForeground 에 전화 하지 않 았 습 니 다.
8387 단어 Android
새로운 Context.startForegroundService()함수 가 프론트 서 비 스 를 시작 합 니 다.현재 배경 에서 실행 되 더 라 도 시스템 은 Context.startForegroundService()를 호출 할 수 있 습 니 다.서 비 스 를 만 든 후 5 초 안에 이 서비스의 startForeground()함 수 를 호출 해 야 합 니 다.app 코드:
Intent intent = new Intent(this, TestService.class);
intent.putExtra("type",1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
} else {
startService(intent);
}
TestService 코드
private NotificationManager notificationManager;
private static final String NOTIFICATION_ID = "channedId";
private static final String NOTIFICATION_NAME = "channedId";
@Override
public void onCreate() {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// NotificationChannel
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel(NOTIFICATION_ID, NOTIFICATION_NAME, NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
startForeground(1,getNotification());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
private Notification getNotification() {
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(" ")
.setContentText(" ");
// Notification ChannelID,
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setChannelId(NOTIFICATION_ID);
}
Notification notification = builder.build();
return notification;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.