Java Code Examples for android.content.pm.PackageManager#getProviderInfo()
The following examples show how to use
android.content.pm.PackageManager#getProviderInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestProvider.java From Popular-Movies-App with Apache License 2.0 | 6 votes |
public void testProviderRegistry() { PackageManager pm = mContext.getPackageManager(); // We define the component name based on the package name from the context and the // MoviesProvider class. ComponentName componentName = new ComponentName(mContext.getPackageName(), MoviesProvider.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: MoviesProvider registered with wrong authority " + providerInfo.authority, providerInfo.authority, MoviesContract.CONTENT_AUTHORITY); } catch (PackageManager.NameNotFoundException e) { // I guess the provider isn't registered correctly. assertTrue("Error: MoviesProvider not registered at " + mContext.getPackageName(), false); } }
Example 2
Source File: TestProvider.java From Advanced_Android_Development with Apache License 2.0 | 6 votes |
public void testProviderRegistry() { PackageManager pm = mContext.getPackageManager(); // We define the component name based on the package name from the context and the // WeatherProvider class. ComponentName componentName = new ComponentName(mContext.getPackageName(), WeatherProvider.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: WeatherProvider registered with authority: " + providerInfo.authority + " instead of authority: " + WeatherContract.CONTENT_AUTHORITY, providerInfo.authority, WeatherContract.CONTENT_AUTHORITY); } catch (PackageManager.NameNotFoundException e) { // I guess the provider isn't registered correctly. assertTrue("Error: WeatherProvider not registered at " + mContext.getPackageName(), false); } }
Example 3
Source File: IssueReporterFragment.java From issue-reporter-android with MIT License | 5 votes |
private String getAuthority(Context context, Class<? extends ContentProvider> providerClass) { PackageManager manager = context.getApplicationContext().getPackageManager(); try { ProviderInfo providerInfo = manager.getProviderInfo( new ComponentName(context, providerClass), PackageManager.GET_META_DATA); return providerInfo.authority; } catch (PackageManager.NameNotFoundException e) { throw new IllegalStateException(e); } }
Example 4
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 5
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 6
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 7
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 8
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 9
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 10
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 11
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 12
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 13
Source File: TestTaskContentProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 14
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 15
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 16
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 17
Source File: TestWeatherProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 18
Source File: TestTaskContentProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 19
Source File: TestTaskContentProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 20
Source File: TestTaskContentProvider.java From android-dev-challenge with Apache License 2.0 | 4 votes |
/** * 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); } }