本文整理汇总了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;
}
示例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);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}