本文整理汇总了Java中android.media.session.MediaSessionManager.addOnActiveSessionsChangedListener方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionManager.addOnActiveSessionsChangedListener方法的具体用法?Java MediaSessionManager.addOnActiveSessionsChangedListener怎么用?Java MediaSessionManager.addOnActiveSessionsChangedListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSessionManager
的用法示例。
在下文中一共展示了MediaSessionManager.addOnActiveSessionsChangedListener方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
@Override
public void onCreate(){
registerReceiver(button,new IntentFilter(MEDIA_ACTION));
mediaSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, componentName);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(componentName);
mediaController = pickController(controllers);
if (mediaController != null) {
mediaController.registerCallback(callback);
meta = mediaController.getMetadata();
updateMetadata();
}
online = true;
} catch (SecurityException e) {
}
}
示例2: onCreate
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
@Override
public void onCreate(){
registerReceiver(button,new IntentFilter(StandardWidget.WIDGET_ACTION));
mediaSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
mediaSessionManager.addOnActiveSessionsChangedListener(sessionListener, componentName);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(componentName);
mediaController = pickController(controllers);
if(mediaController!=null) {
mediaController.registerCallback(callback);
meta = mediaController.getMetadata();
updateMetadata();
}
online = true;
sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
示例3: sync
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
public void sync() {
mDevice.enableNotify(mediaCommandsCharac, commandsListener);
try {
mMediaSessionManager = (MediaSessionManager) mCtx.getSystemService(Context.MEDIA_SESSION_SERVICE);
List<MediaController> controllers = mMediaSessionManager.getActiveSessions(new ComponentName(mCtx, NLService.class));
onActiveSessionsChanged(controllers);
mMediaSessionManager.addOnActiveSessionsChangedListener(this, new ComponentName(mCtx, NLService.class));
} catch (SecurityException e) {
Log.w("MediaService", "No Notification Access");
}
}
示例4: onCreate
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
ScroballApplication application = (ScroballApplication) getApplication();
sharedPreferences = application.getSharedPreferences();
ConnectivityManager connectivityManager =
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
ScroballDB scroballDB = application.getScroballDB();
ScrobbleNotificationManager scrobbleNotificationManager =
new ScrobbleNotificationManager(this, sharedPreferences);
LastfmClient lastfmClient = application.getLastfmClient();
Scrobbler scrobbler =
new Scrobbler(lastfmClient, scrobbleNotificationManager, scroballDB, connectivityManager);
playbackTracker = new PlaybackTracker(scrobbleNotificationManager, scrobbler);
Log.d(TAG, "NotificationListenerService started");
MediaSessionManager mediaSessionManager =
(MediaSessionManager)
getApplicationContext().getSystemService(Context.MEDIA_SESSION_SERVICE);
ComponentName componentName = new ComponentName(this, this.getClass());
mediaSessionManager.addOnActiveSessionsChangedListener(this, componentName);
NetworkStateReceiver networkStateReceiver = new NetworkStateReceiver(scrobbler);
IntentFilter filter = new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
this.registerReceiver(networkStateReceiver, filter);
// Trigger change event with existing set of sessions.
List<MediaController> initialSessions = mediaSessionManager.getActiveSessions(componentName);
onActiveSessionsChanged(initialSessions);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
示例5: RemoteControlLollipop
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
protected RemoteControlLollipop(Context context, Class<? extends NotificationListenerService> clazz) {
super(context);
mControllerService = new ComponentName(context, clazz);
mControllers = new ConcurrentHashMap<>();
mMediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
mMediaSessionManager.addOnActiveSessionsChangedListener(this, mControllerService);
mRegistered = true;
}
示例6: 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);
}
示例7: 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));
}
示例8: onCreate
import android.media.session.MediaSessionManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
sRunning = true;
try {
mediaControllerCallback = new MediaControllerCallback(this);
MediaSessionManager.OnActiveSessionsChangedListener sessionsChangedListener =
list -> mediaControllerCallback.registerActiveSessionCallback(ScrobblerService.this, list);
listener = new WeakReference<>(sessionsChangedListener);
MediaSessionManager manager = ((MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE));
ComponentName className = new ComponentName(getApplicationContext(), NotificationListenerService.class);
manager.addOnActiveSessionsChangedListener(sessionsChangedListener, className);
List<MediaController> controllers = manager.getActiveSessions(className);
mediaControllerCallback.registerActiveSessionCallback(ScrobblerService.this, controllers);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SharedPreferences current = getSharedPreferences("current_music", Context.MODE_PRIVATE);
String artist = current.getString("artist", "");
String track = current.getString("track", "");
startForeground(NOTIFICATION_ID, NotificationUtil.makeNotification(this, artist, track, 0L, false, false));
}
if (!controllers.isEmpty())
mediaControllerCallback.broadcastControllerState(this, controllers.get(0), null);
} catch (Exception e) {
e.printStackTrace();
return;
}
Log.d("geecko", "mediaControllerCallback registered");
}