android.support.v4.media.MediaBrowserServiceCompat Java Examples

The following examples show how to use android.support.v4.media.MediaBrowserServiceCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaButtonReceiver.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    Intent queryIntent = new Intent("android.intent.action.MEDIA_BUTTON");
    queryIntent.setPackage(context.getPackageName());
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, 0);
    if (resolveInfos.isEmpty()) {
        queryIntent.setAction(MediaBrowserServiceCompat.SERVICE_INTERFACE);
        resolveInfos = pm.queryIntentServices(queryIntent, 0);
    }
    if (resolveInfos.isEmpty()) {
        throw new IllegalStateException("Could not find any Service that handles android.intent.action.MEDIA_BUTTON or a media browser service implementation");
    } else if (resolveInfos.size() != 1) {
        throw new IllegalStateException("Expected 1 Service that handles " + queryIntent.getAction() + ", found " + resolveInfos.size());
    } else {
        ResolveInfo resolveInfo = (ResolveInfo) resolveInfos.get(0);
        intent.setComponent(new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name));
        context.startService(intent);
    }
}
 
Example #2
Source File: MediaBrowserHelper.java    From android-MediaBrowserService with Apache License 2.0 5 votes vote down vote up
public MediaBrowserHelper(Context context,
                          Class<? extends MediaBrowserServiceCompat> serviceClass) {
    mContext = context;
    mMediaBrowserServiceClass = serviceClass;

    mMediaBrowserConnectionCallback = new MediaBrowserConnectionCallback();
    mMediaControllerCallback = new MediaControllerCallback();
    mMediaBrowserSubscriptionCallback = new MediaBrowserSubscriptionCallback();
}
 
Example #3
Source File: TrackNotification.java    From Melophile with Apache License 2.0 4 votes vote down vote up
public TrackNotification(MediaBrowserServiceCompat service) {
  this.service = service;
  this.manager = NotificationManagerCompat.from(service);
  this.token = service.getSessionToken();
  manager.cancel(NOTIFICATION_ID);
}