Tabnine Logo
MediaSessionManager.getActiveSessions
Code IndexAdd Tabnine to your IDE (free)

How to use
getActiveSessions
method
in
android.media.session.MediaSessionManager

Best Java code snippets using android.media.session.MediaSessionManager.getActiveSessions (Showing top 8 results out of 315)

origin: stackoverflow.com

 MediaSessionManager mm = (MediaSessionManager) this.getSystemService(
  Context.MEDIA_SESSION_SERVICE);
List<MediaController> controllers = mm.getActiveSessions(
  new ComponentName(this, NotificationListener.class));
Log.i(TAG, "found " + controllers.size() + " controllers");
origin: rockon999/LeanbackLauncher

  public void checkForMediaSession() {
    MediaSessionManager manager = (MediaSessionManager) this.mContext.getApplicationContext().getSystemService("media_session");
    if (manager != null) {
      if (!this.mIsTestRunning) {
        new MediaSession(this.mContext.getApplicationContext(), "NowPlayCardListener").release();
      }
      onActiveSessionsChanged(manager.getActiveSessions(null));
    }
  }
}
origin: stackoverflow.com

 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
void sendHeadsetHookLollipop() {
  MediaSessionManager mediaSessionManager =  (MediaSessionManager) getApplicationContext().getSystemService(Context.MEDIA_SESSION_SERVICE);

  try {
    List<MediaController> mediaControllerList = mediaSessionManager.getActiveSessions 
           (new ComponentName(getApplicationContext(), NotificationReceiverService.class));

    for (MediaController m : mediaControllerList) {
       if ("com.android.server.telecom".equals(m.getPackageName())) {
         m.dispatchMediaButtonEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
         log.info("HEADSETHOOK sent to telecom server");
         break;
       }
    }
  } catch (SecurityException e) {
    log.error("Permission error. Access to notification not granted to the app.");      
  }  
}
origin: KDE/kdeconnect-android

@Override
public boolean onCreate() {
  if (!hasPermission())
    return false;
  players = new HashMap<>();
  try {
    MediaSessionManager manager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
    if (null == manager)
      return false;
    manager.addOnActiveSessionsChangedListener(MprisReceiverPlugin.this, new ComponentName(context, NotificationReceiver.class), new Handler(Looper.getMainLooper()));
    createPlayers(manager.getActiveSessions(new ComponentName(context, NotificationReceiver.class)));
    sendPlayerList();
  } catch (Exception e) {
    Log.e(TAG, "Exception", e);
  }
  return true;
}
origin: renyuneyun/Easer

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private boolean handleOnApi21(@ValidData @NonNull MediaControlOperationData data) {
  int keyCode = toKeyCode(data.choice);
  KeyEvent keyEvent_down = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
  KeyEvent keyEvent_up = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
  ComponentName myNotificationListenerComponent = new ComponentName(context, MediaControlHelperNotificationListenerService.class);
  MediaSessionManager mediaSessionManager = ((MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE));
  if (mediaSessionManager == null) {
    Logger.e("MediaSessionManager is null.");
    return false;
  }
  List<MediaController> activeSessions = mediaSessionManager.getActiveSessions(myNotificationListenerComponent);
  if (activeSessions.size() > 0) {
    MediaController mediaController = activeSessions.get(0);
    mediaController.dispatchMediaButtonEvent(keyEvent_down);
    mediaController.dispatchMediaButtonEvent(keyEvent_up);
  }
  return true;
}
origin: rockon999/LeanbackLauncher

private void setPendingIntentAndPackage(NowPlayingCardData data, MediaSessionManager sessionManager) {
  data.clickIntent = null;
  data.playerPackage = null;
  List<MediaController> controllers = sessionManager.getActiveSessions(null);
  MediaController controller = null;
  for (int i = 0; i < controllers.size(); i++) {
    MediaController aController = (MediaController) controllers.get(i);
    if ((aController.getFlags() & 2) != 0) {
      controller = aController;
      break;
    }
  }
  if (controller != null) {
    data.playerPackage = controller.getPackageName();
    data.clickIntent = controller.getSessionActivity();
    if (data.clickIntent == null) {
      data.clickIntent = getPendingIntentFallback(data.playerPackage);
    }
  }
}
origin: MoMoWait/LeanbackLauncher

private void setPendingIntentAndPackage(NowPlayingCardData data, MediaSessionManager sessionManager) {
  data.clickIntent = null;
  data.playerPackage = null;
  List<MediaController> controllers = sessionManager.getActiveSessions(null);
  MediaController controller = null;
  for (int i = 0; i < controllers.size(); i++) {
    MediaController aController = (MediaController) controllers.get(i);
    if ((aController.getFlags() & 2) != 0) {
      controller = aController;
      break;
    }
  }
  if (controller != null) {
    data.playerPackage = controller.getPackageName();
    data.clickIntent = controller.getSessionActivity();
    if (data.clickIntent == null) {
      data.clickIntent = getPendingIntentFallback(data.playerPackage);
    }
  }
}
origin: tomahawk-player/tomahawk-android

manager.addOnActiveSessionsChangedListener(mSessionsChangedListener, componentName);
synchronized (this) {
  mActiveSessions = manager.getActiveSessions(componentName);
  registerSessionCallbacks();
android.media.sessionMediaSessionManagergetActiveSessions

Popular methods of MediaSessionManager

  • addOnActiveSessionsChangedListener
  • removeOnActiveSessionsChangedListener

Popular in Java

  • Start an intent from android
  • putExtra (Intent)
  • startActivity (Activity)
  • scheduleAtFixedRate (Timer)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Reference (javax.naming)
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JTable (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now