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