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


Java PackageManager.queryIntentServices方法代码示例

本文整理汇总了Java中android.content.pm.PackageManager.queryIntentServices方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.queryIntentServices方法的具体用法?Java PackageManager.queryIntentServices怎么用?Java PackageManager.queryIntentServices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.pm.PackageManager的用法示例。


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

示例1: isRecognitionServiceInstalled

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * @return true iff a RecognitionService with the given component name is installed
 */
public static boolean isRecognitionServiceInstalled(PackageManager pm, ComponentName componentName) {
    List<ResolveInfo> services = pm.queryIntentServices(
            new Intent(RecognitionService.SERVICE_INTERFACE), 0);
    for (ResolveInfo ri : services) {
        ServiceInfo si = ri.serviceInfo;
        if (si == null) {
            Log.i("serviceInfo == null");
            continue;
        }
        if (componentName.equals(new ComponentName(si.packageName, si.name))) {
            return true;
        }
    }
    return false;
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:19,代码来源:RecognitionServiceManager.java

示例2: createExplicitFromImplicitIntent

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/***
 * Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
 * "java.lang.IllegalArgumentException: Service Intent must be explicit"
 * <p>
 * If you are using an implicit intent, and know only 1 target would answer this intent,
 * This method will help you turn the implicit intent into the explicit form.
 * <p>
 * Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
 *
 * @param context
 * @param implicitIntent - The original implicit intent
 * @return Explicit Intent created from the implicit original intent
 */
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
    // Retrieve all services that can match the given intent
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);

    // Make sure only one match was found
    if (resolveInfo == null || resolveInfo.size() != 1) {
        return null;
    }

    // Get component info and create ComponentName
    ResolveInfo serviceInfo = resolveInfo.get(0);
    String packageName = serviceInfo.serviceInfo.packageName;
    String className = serviceInfo.serviceInfo.name;
    ComponentName component = new ComponentName(packageName, className);

    // Create a new intent. Use the old one for extras and such reuse
    Intent explicitIntent = new Intent(implicitIntent);

    // Set the component to be explicit
    explicitIntent.setComponent(component);

    return explicitIntent;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:38,代码来源:Utils.java

示例3: onReceive

import android.content.pm.PackageManager; //导入方法依赖的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

示例4: t

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static List<ComponentName> t(Context context) {
    z.b();
    List<ComponentName> arrayList = new ArrayList();
    PackageManager packageManager = context.getPackageManager();
    Intent intent = new Intent();
    intent.setAction(z[98]);
    List queryIntentServices = packageManager.queryIntentServices(intent, 0);
    if (queryIntentServices == null || queryIntentServices.size() == 0) {
        return null;
    }
    for (int i = 0; i < queryIntentServices.size(); i++) {
        ServiceInfo serviceInfo = ((ResolveInfo) queryIntentServices.get(i)).serviceInfo;
        String str = serviceInfo.name;
        String str2 = serviceInfo.packageName;
        if (serviceInfo.exported && serviceInfo.enabled && !e.c.equals(str2)) {
            new StringBuilder(z[97]).append(str2).append("/").append(str).append("}");
            z.b();
            arrayList.add(new ComponentName(str2, str));
        }
    }
    return arrayList;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:a.java

示例5: getServices

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * @return list of currently installed RecognitionService component names flattened to short strings
 */
public List<String> getServices(PackageManager pm) {
    List<String> services = new ArrayList<>();
    int flags = 0;
    //int flags = PackageManager.GET_META_DATA;
    List<ResolveInfo> infos = pm.queryIntentServices(
            new Intent(RecognitionService.SERVICE_INTERFACE), flags);

    for (ResolveInfo ri : infos) {
        ServiceInfo si = ri.serviceInfo;
        if (si == null) {
            Log.i("serviceInfo == null");
            continue;
        }
        String pkg = si.packageName;
        String cls = si.name;
        // TODO: process si.metaData
        String component = (new ComponentName(pkg, cls)).flattenToShortString();
        if (!mCombosExcluded.contains(component)) {
            services.add(component);
        }
    }
    return services;
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:27,代码来源:RecognitionServiceManager.java

示例6: connectToMediaBrowserPackage

import android.content.pm.PackageManager; //导入方法依赖的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

示例7: createExplicitFromImplicitIntent

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/***
 * Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
 * "java.lang.IllegalArgumentException: Service Intent must be explicit"
 *
 * If you are using an implicit intent, and know only 1 target would answer this intent,
 * This method will help you turn the implicit intent into the explicit form.
 *
 * Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
 * @param context
 * @param implicitIntent - The original implicit intent
 * @return Explicit Intent created from the implicit original intent
 */
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
    // Retrieve all services that can match the given intent
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);

    // Make sure only one match was found
    if (resolveInfo == null || resolveInfo.size() != 1) {
        return implicitIntent;
    }

    // Get component info and create ComponentName
    ResolveInfo serviceInfo = resolveInfo.get(0);
    String packageName = serviceInfo.serviceInfo.packageName;
    String className = serviceInfo.serviceInfo.name;
    if(packageName!=null && packageName.equals(context.getPackageName())) {
        ComponentName component = new ComponentName(packageName, className);

        // Create a new intent. Use the old one for extras and such reuse
        Intent explicitIntent = new Intent(implicitIntent);

        // Set the component to be explicit
        explicitIntent.setComponent(component);

        return explicitIntent;
    }else{
        return implicitIntent;
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:41,代码来源:ServiceDetector.java


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