本文整理汇总了Java中android.media.session.MediaSessionManager.removeOnActiveSessionsChangedListener方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionManager.removeOnActiveSessionsChangedListener方法的具体用法?Java MediaSessionManager.removeOnActiveSessionsChangedListener怎么用?Java MediaSessionManager.removeOnActiveSessionsChangedListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSessionManager
的用法示例。
在下文中一共展示了MediaSessionManager.removeOnActiveSessionsChangedListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStart
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onStart(Object... objects) {
super.onStart();
// Init a new thread.
mThread = new T(this);
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.start();
// Media session manager leaks/holds the context for too long.
// Don't let it to leak the activity, better lak the whole app.
final Context context = mContext.getApplicationContext();
mMediaSessionManager = (MediaSessionManager) context
.getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
mMediaSessionManager.addOnActiveSessionsChangedListener(mSessionListener, mComponent);
mSessionListener.setMediaController(this);
mSessionListening = true;
} catch (SecurityException exception) {
Log.w(TAG, "Failed to start Lollipop media controller: " + exception.getMessage());
// Try to unregister it, just it case.
try {
mMediaSessionManager.removeOnActiveSessionsChangedListener(mSessionListener);
} catch (Exception e) { /* unused */ } finally {
mMediaSessionManager = null;
mSessionListening = false;
}
// Media controller needs notification listener service
// permissions to be granted.
return;
}
List<MediaController> controllers = mMediaSessionManager.getActiveSessions(mComponent);
mSessionListener.onActiveSessionsChanged(controllers);
}
示例2: registerFallbackControllerCallback
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void registerFallbackControllerCallback(Context context, MediaControllerCallback controllerCallback) {
MediaSessionManager mediaSessionManager = ((MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE));
ComponentName className = new ComponentName(context.getApplicationContext(), NotificationListenerService.class);
if (sessionListener != null)
mediaSessionManager.removeOnActiveSessionsChangedListener(sessionListener);
sessionListener = list -> controllerCallback.registerActiveSessionCallback(context, list);
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, className);
controllerCallback.registerActiveSessionCallback(context, mediaSessionManager.getActiveSessions(className));
}