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

How to use
MediaSessionManager
in
android.media.session

Best Java code snippets using android.media.session.MediaSessionManager (Showing top 10 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: 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: rockon999/LeanbackLauncher

public synchronized void setRemoteControlListener(Listener listener) throws RemoteException {
  if (Log.isLoggable("NowPlayCardListener", 3)) {
    Log.d("NowPlayCardListener", "setRemoteControlListener: " + listener);
  }
  MediaSessionManager manager = (MediaSessionManager) this.mContext.getApplicationContext().getSystemService("media_session");
  if (listener != null) {
    manager.addOnActiveSessionsChangedListener(this, null);
    this.mNowPlayCardListener = listener;
    checkForMediaSession();
  } else {
    manager.removeOnActiveSessionsChangedListener(this);
    this.mNowPlayCardListener = null;
    updateMediaSessionCallback(null);
  }
}
origin: tomahawk-player/tomahawk-android

/**
 * Disables RemoteController.
 */
public void setRemoteControllerDisabled() {
  Log.d(TAG, "setRemoteControllerDisabled");
  if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
    Object service = TomahawkApp.getContext().getSystemService(Context.AUDIO_SERVICE);
    if (service instanceof AudioManager
        && ((AudioManager) service).registerRemoteController(mRemoteController)) {
      ((AudioManager) service).unregisterRemoteController(mRemoteController);
    }
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Object service =
        TomahawkApp.getContext().getSystemService(Context.MEDIA_SESSION_SERVICE);
    if (service instanceof MediaSessionManager) {
      MediaSessionManager manager = (MediaSessionManager) service;
      if (mSessionsChangedListener != null) {
        manager.removeOnActiveSessionsChangedListener(mSessionsChangedListener);
      }
      synchronized (this) {
        unregisterSessionCallbacks();
        mActiveSessions = new ArrayList<>();
      }
    }
  }
}
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: tomahawk-player/tomahawk-android

manager.addOnActiveSessionsChangedListener(mSessionsChangedListener, componentName);
synchronized (this) {
  mActiveSessions = manager.getActiveSessions(componentName);
  registerSessionCallbacks();
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: 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);
    }
  }
}
android.media.sessionMediaSessionManager

Most used methods

  • getActiveSessions
  • addOnActiveSessionsChangedListener
  • removeOnActiveSessionsChangedListener

Popular in Java

  • Running tasks concurrently on multiple threads
  • notifyDataSetChanged (ArrayAdapter)
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JLabel (javax.swing)
  • Top plugins for WebStorm
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