Public int onStartCommand (Intent Intent, int flags, int startId) {
The d (" service ", "onStartCommand: start");
Notification. Builder Notification;
Intent mintent=new Intent (enclosing getApplicationContext (), outkeeplive. Class);
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. O {
NotificationChannel channel=new NotificationChannel (" com. ZXB. Service. Channel ", ". Com. ZXB. Service channel, "NotificationManager. IMPORTANCE_LOW);
NotificationManager nm=(NotificationManager) getSystemService (Context. NOTIFICATION_SERVICE);
Nm. CreateNotificationChannel (channel);
Notification=new notification. Builder (this, "com. ZXB. Service. Channel");
} else {
Notification=new notification. Builder (this);
}
Notification. SetContentTitle (" my services ");
Start notification. SetContentText (" service ");
Notification. SetSmallIcon (R.d rawable. Xiangcheng);
Notification. SetContentIntent (PendingIntent. GetActivity (enclosing getApplicationContext (), 0, mintent, 0));
Notification. SetOngoing (true);
StartForeground (serviceId, notification. The build ());
The d (" service ", "onStartCommand: end");
Return START_REDELIVER_INTENT;
}
XML service androidmanifest.
The android: name="myservice"
Android: enabled="true"
Android: exported="true" & gt;
In the activity called
Intent Intent=new Intent ();
Intent. SetComponent (new the ComponentName (com. ZXB. "service", "com. ZXB. Service. Myservice"));
Intent. AddFlags (intent. FLAG_ACTIVITY_CLEAR_TASK | intent. FLAG_ACTIVITY_NEW_TASK | intent. FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
The d (" to start the service ", "onResume: com. ZXB. Service");
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. O {
The d (" start services ", "onResume: front desk service");
StartForegroundService (intent);
} else {
The d (" start services ", "onResume: background services");
StartService (intent);
}
On the android 6.0 operating normally, and can't start on oppo android 7.0
CodePudding user response:
Just the same, what is this error, run on the android 6.0 operating normally, and can't start on oppo android 7.0CodePudding user response:
Is there a great god know