org.robolectric.res.builder.RobolectricPackageManager Java Examples

The following examples show how to use org.robolectric.res.builder.RobolectricPackageManager. 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: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Register a handler in the package manager for a image capture intent
 */
private void registerMediaStoreIntentHandler()
{
    // Add something that will 'handle' the media capture intent
    RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());

    ResolveInfo info = new ResolveInfo();
    info.isDefault = true;

    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.packageName = "does.not.matter";
    info.activityInfo = new ActivityInfo();
    info.activityInfo.applicationInfo = applicationInfo;
    info.activityInfo.name = "DoesNotMatter";

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    packageManager.addResolveInfoForIntent(intent, info);
}
 
Example #2
Source File: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,114.1043205";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isTrue();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
Example #3
Source File: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_false_when_nothing_on_the_device_can_open_the_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), (ResolveInfo) null);

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isFalse();
    assertThat(startedIntent).isNull();
}
 
Example #4
Source File: IntentsTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_start_external_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    Intents.startExternalUrl(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
Example #5
Source File: FullEnvTestLifeCycle.java    From matomo-sdk-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Application createApplication(Method method, AndroidManifest appManifest, Config config) {
    // FIXME If a future version of Robolectric implements "setInstallerPackageName", remove this.
    RobolectricPackageManager oldManager = Robolectric.packageManager;
    RobolectricPackageManager newManager = new FullEnvPackageManager();
    for (PackageInfo pkg : oldManager.getInstalledPackages(0))
        newManager.addPackage(pkg);
    Robolectric.packageManager = newManager;
    return new MatomoTestApplication();
}
 
Example #6
Source File: RateThisAppTest.java    From Android-RateThisApp with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws PackageManager.NameNotFoundException {
    Context context = RuntimeEnvironment.application.getApplicationContext();

    // Assume app just installed
    RobolectricPackageManager roboPackMan = RuntimeEnvironment.getRobolectricPackageManager();
    PackageInfo pkgInfo = roboPackMan.getPackageInfo(context.getPackageName(), 0);
    pkgInfo.firstInstallTime = System.currentTimeMillis();
}
 
Example #7
Source File: ActivityUtilsTest.java    From android-utilset with Apache License 2.0 4 votes vote down vote up
private void addInstalledPackage(String packageName) {
	RobolectricPackageManager pm = Robolectric.packageManager;
	PackageInfo packInfo = new PackageInfo();
	packInfo.packageName = packageName;
	pm.addPackage(packInfo);
}
 
Example #8
Source File: IabHelperTest.java    From pay-me with Apache License 2.0 4 votes vote down vote up
private Context registerServiceWithPackageManager() {
    Context context = Robolectric.application;
    RobolectricPackageManager pm = (RobolectricPackageManager) context.getPackageManager();
    pm.addResolveInfoForIntent(IabHelper.BIND_BILLING_SERVICE, new ResolveInfo());
    return context;
}