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


Java PackageManager.getProviderInfo方法代码示例

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


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

示例1: testProviderRegistry

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Test
public void testProviderRegistry() {
    Context appContext = InstrumentationRegistry.getTargetContext();
    PackageManager pm = appContext.getPackageManager();

    // We define the component name based on the package name from the context and the
    // Provider class.
    ComponentName componentName = new ComponentName(appContext.getPackageName(),
            FavoritesProvider.class.getName());
    try {
        // Fetch the provider info using the component name from the PackageManager
        // This throws an exception if the provider isn't registered.
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);

        // Make sure that the registered authority matches the authority from the Contract.
        assertEquals("Error: FavoritesProvider registered with authority: " + providerInfo.authority
                + " instead of authority: " + FavoritesContract.AUTHORITY,
                providerInfo.authority, FavoritesContract.AUTHORITY);
    } catch (PackageManager.NameNotFoundException e) {
        // I guess the provider isn't registered correctly.
        assertTrue("Error: FavoritesProvider not registered at " + appContext.getPackageName(),
                false);
    }
}
 
开发者ID:an-garcia,项目名称:MovieGuide,代码行数:25,代码来源:TestProvider.java

示例2: testProviderRegistry

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public void testProviderRegistry() {
    PackageManager pm = mContext.getPackageManager();

    ComponentName componentName = new ComponentName(mContext.getPackageName(),
            LeaderProvider.class.getName());
    try {
        // Fetch the provider info using the component name from the PackageManager
        // This throws an exception if the provider isn't registered.
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);

        // Make sure that the registered authority matches the authority from the Contract.
        assertEquals("Error: LeaderProvider registered with authority: " + providerInfo.authority +
                " instead of authority: " + LeaderContract.CONTENT_AUTHORITY,
                providerInfo.authority, LeaderContract.CONTENT_AUTHORITY);
    } catch (PackageManager.NameNotFoundException e) {
        assertTrue("Error: LeaderProvider not registered at " + mContext.getPackageName(),
                false);
    }
}
 
开发者ID:Protino,项目名称:CodeWatch,代码行数:20,代码来源:TestProvider.java

示例3: testProviderRegistry

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
开发者ID:rashikaranpuria,项目名称:ubiquitous,代码行数:63,代码来源:TestWeatherProvider.java

示例4: testProviderRegistry

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String taskProviderClassName = TaskContentProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, taskProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = packageName;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: TaskContentProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: TaskContentProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:57,代码来源:TestTaskContentProvider.java


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