Advertisement
Guest User

Untitled

a guest
May 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Intent serviceIntent = new Intent(this, group.ytos.u.Services.NewsService.class);
  2.  
  3. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  4. final Context applicationContext = getApplicationContext();
  5. applicationContext.bindService(serviceIntent, new ServiceConnection() {
  6. @Override
  7. public void onServiceConnected(ComponentName name, IBinder binder) {
  8. if (binder instanceof ServiceBinder) {
  9. ServiceBinder serviceBinder = (ServiceBinder) binder;
  10. group.ytos.u.Services.NewsService newsService = serviceBinder.getService();
  11. if (newsService != null) {
  12. newsService.forceForeground();
  13. }
  14. }
  15. applicationContext.unbindService(this);
  16. }
  17.  
  18. @Override
  19. public void onServiceDisconnected(ComponentName name) {
  20.  
  21. }
  22. }, Context.BIND_AUTO_CREATE);
  23. Log.d(TAG, "onCreateView: android 8");
  24. this.startForegroundService(serviceIntent);
  25. } else {
  26. Log.d(TAG, "onCreateView: android 7");
  27. this.startService(serviceIntent);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement