Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent serviceIntent = new Intent(this, group.ytos.u.Services.NewsService.class);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- final Context applicationContext = getApplicationContext();
- applicationContext.bindService(serviceIntent, new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder binder) {
- if (binder instanceof ServiceBinder) {
- ServiceBinder serviceBinder = (ServiceBinder) binder;
- group.ytos.u.Services.NewsService newsService = serviceBinder.getService();
- if (newsService != null) {
- newsService.forceForeground();
- }
- }
- applicationContext.unbindService(this);
- }
- @Override
- public void onServiceDisconnected(ComponentName name) {
- }
- }, Context.BIND_AUTO_CREATE);
- Log.d(TAG, "onCreateView: android 8");
- this.startForegroundService(serviceIntent);
- } else {
- Log.d(TAG, "onCreateView: android 7");
- this.startService(serviceIntent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement