当前位置: 首页>>代码示例>>Java>>正文


Java MediaBrowserServiceCompat类代码示例

本文整理汇总了Java中android.support.v4.media.MediaBrowserServiceCompat的典型用法代码示例。如果您正苦于以下问题:Java MediaBrowserServiceCompat类的具体用法?Java MediaBrowserServiceCompat怎么用?Java MediaBrowserServiceCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MediaBrowserServiceCompat类属于android.support.v4.media包,在下文中一共展示了MediaBrowserServiceCompat类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMediaApps

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
/**
 * Finds installed packages that have registered a
 * {@link android.service.media.MediaBrowserService} or
 * {@link android.support.v4.media.MediaBrowserServiceCompat} service by
 * looking for packages that have services that respond to the
 * "android.media.browse.MediaBrowserService" action.
 */
@Override
protected List<MediaAppEntry> getMediaApps() {
    final List<MediaAppEntry> mediaApps = new ArrayList<>();

    // Build an Intent that only has the MediaBrowserService action and query
    // the PackageManager for apps that have services registered that can
    // receive it.
    final Intent mediaBrowserIntent =
            new Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE);
    final List<ResolveInfo> services =
            mPackageManager.queryIntentServices(mediaBrowserIntent,
                    PackageManager.GET_RESOLVED_FILTER);

    if (services != null && !services.isEmpty()) {
        for (final ResolveInfo info : services) {
            mediaApps.add(
                    MediaAppEntry.fromBrowseService(info.serviceInfo, mPackageManager));
        }
    }
    return mediaApps;
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:29,代码来源:LaunchActivity.java

示例2: onReceive

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
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);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:MediaButtonReceiver.java

示例3: connectToMediaBrowserPackage

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
private void connectToMediaBrowserPackage(final String packageName) {
    final PackageManager packageManager = getPackageManager();

    final Intent mediaBrowserIntent = new Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE);
    final List<ResolveInfo> services =
            packageManager.queryIntentServices(mediaBrowserIntent,
                    PackageManager.GET_RESOLVED_FILTER);
    for (ResolveInfo info : services) {
        if (info.serviceInfo.packageName.equals(packageName)) {
            final Bitmap icon = BitmapUtils.convertDrawable(
                    getResources(), info.loadIcon(packageManager));
            final String name = info.loadLabel(packageManager).toString();

            setupToolbar(name, icon);
            MediaAppEntry appEntry = MediaAppEntry.fromBrowseService(
                    info.serviceInfo, packageManager);
            appEntry.getSessionToken(this, new MediaAppEntry.SessionTokenAvailableCallback() {
                @Override
                public void onSuccess(MediaSessionCompat.Token sessionToken) {
                    mMediaAppDetails = new MediaAppDetails(name, icon, sessionToken);
                    setupMediaController();
                }

                @Override
                public void onFailure() {
                    showToastAndFinish(getString(R.string.connection_failed_msg, packageName));
                }
            });
            return;
        }
    }
    // Failed to find package.
    showToastAndFinish(getString(R.string.no_app_for_package, packageName));
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:35,代码来源:MediaAppControllerActivity.java

示例4: onGetRoot

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid,
                             Bundle rootHints) {
    LogHelper.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName,
            "; clientUid=" + clientUid + " ; rootHints=", rootHints);
    // To ensure you are not allowing any arbitrary app to browse your app's contents, you
    // need to check the origin:
    if (!mPackageValidator.isCallerAllowed(this, clientPackageName, clientUid)) {
        // If the request comes from an untrusted package, return an empty browser root.
        // If you return null, then the media browser will not be able to connect and
        // no further calls will be made to other media browsing methods.
        LogHelper.i(TAG, "OnGetRoot: Browsing NOT ALLOWED for unknown caller. "
                + "Returning empty browser root so all apps can use MediaController."
                + clientPackageName);
        return new MediaBrowserServiceCompat.BrowserRoot(MEDIA_ID_EMPTY_ROOT, null);
    }
    //noinspection StatementWithEmptyBody
    if (CarHelper.isValidCarPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library to show a different subset
        // when connected to the car, this is where you should handle it.
        // If you want to adapt other runtime behaviors, like tweak ads or change some behavior
        // that should be different on cars, you should instead use the boolean flag
        // set by the BroadcastReceiver mCarConnectionReceiver (mIsConnectedToCar).
    }
    //noinspection StatementWithEmptyBody
    if (WearHelper.isValidWearCompanionPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library for when browsing from a
        // Wear device, you should return a different MEDIA ROOT here, and then,
        // on onLoadChildren, handle it accordingly.
    }

    return new BrowserRoot(MEDIA_ID_ROOT, null);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:34,代码来源:MusicService.java

示例5: onGetRoot

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
@Nullable
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
    // Credit: https://github.com/googlesamples/android-UniversalMusicPlayer (->  MusicService)
    LogHelper.v(LOG_TAG, "OnGetRoot: clientPackageName=" + clientPackageName + "; clientUid=" + clientUid + " ; rootHints=" + rootHints);
    // to ensure you are not allowing any arbitrary app to browse your app's contents, you need to check the origin:
    if (!mPackageValidator.isCallerAllowed(this, clientPackageName, clientUid)) {
        // request comes from an untrusted package
        LogHelper.i(LOG_TAG, "OnGetRoot: Browsing NOT ALLOWED for unknown caller. "
                + "Returning empty browser root so all apps can use MediaController."
                + clientPackageName);
        return new MediaBrowserServiceCompat.BrowserRoot(MEDIA_ID_EMPTY_ROOT, null);
    }
    return new BrowserRoot(MEDIA_ID_ROOT, null);
}
 
开发者ID:y20k,项目名称:transistor,代码行数:16,代码来源:PlayerService.java

示例6: onGetRoot

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
@Nullable
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
    return new MediaBrowserServiceCompat.BrowserRoot(MusicProvider.MEDIA_ID_ARTIST, null);
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:6,代码来源:MusicService.java

示例7: TrackNotification

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
public TrackNotification(MediaBrowserServiceCompat service){
    this.service=service;
    this.manager=NotificationManagerCompat.from(service);
    this.token=service.getSessionToken();
    manager.cancel(NOTIFICATION_ID);
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:7,代码来源:TrackNotification.java

示例8: getBrowserRoot

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
public MediaBrowserServiceCompat.BrowserRoot getBrowserRoot(@NonNull String clientPackageName,
                                                                     int clientUid,
                                                                     Bundle rootHints) {
    return new MediaBrowserServiceCompat.BrowserRoot(MEDIA_ID_SCHEME + "://", null);
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:6,代码来源:MediaProvider.java

示例9: onLoadChildren

import android.support.v4.media.MediaBrowserServiceCompat; //导入依赖的package包/类
public void onLoadChildren(
        @NonNull final String parentMediaId,
        @NonNull final MediaBrowserServiceCompat.Result<List<MediaBrowserCompat.MediaItem>> result) {
    result.sendResult(Collections.<MediaBrowserCompat.MediaItem>emptyList());
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:6,代码来源:MediaProvider.java


注:本文中的android.support.v4.media.MediaBrowserServiceCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。