當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。