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


Java RobolectricPackageManager.addResolveInfoForIntent方法代码示例

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


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

示例1: registerMediaStoreIntentHandler

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:brarcher,项目名称:gift-card-guard,代码行数:22,代码来源:GiftCardViewActivityTest.java

示例2: should_start_url_intent

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@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);
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:19,代码来源:IntentsTest.java

示例3: should_return_false_when_nothing_on_the_device_can_open_the_uri

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@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();
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例4: should_start_external_uri

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@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);
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例5: registerIntentHandler

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
private void registerIntentHandler(String handler)
{
    // Add something that will 'handle' the given intent type
    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";
    info.activityInfo.exported = true;

    Intent intent = new Intent(handler);

    if(handler.equals(Intent.ACTION_GET_CONTENT))
    {
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
    }

    packageManager.addResolveInfoForIntent(intent, info);
}
 
开发者ID:brarcher,项目名称:loyalty-card-locker,代码行数:26,代码来源:ImportExportActivityTest.java

示例6: testDownloadContent

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@Test
public void testDownloadContent() {
    ResolveInfo resolverInfo = new ResolveInfo();
    resolverInfo.activityInfo = new ActivityInfo();
    resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
    resolverInfo.activityInfo.applicationInfo.packageName =
            ListActivity.class.getPackage().getName();
    resolverInfo.activityInfo.name = ListActivity.class.getName();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    final String url = "http://example.com/file.doc";
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), resolverInfo);

    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
    when(item.getUrl()).thenReturn(url);
    shadowWebView.getDownloadListener().onDownloadStart(url, "", "", "", 0l);
    assertThat((View) activity.findViewById(R.id.empty)).isVisible();
    activity.findViewById(R.id.download_button).performClick();
    assertNotNull(shadowOf(activity).getNextStartedActivity());
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:21,代码来源:WebFragmentTest.java

示例7: testDownloadPdf

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@Test
public void testDownloadPdf() throws InterruptedException {
    ResolveInfo resolverInfo = new ResolveInfo();
    resolverInfo.activityInfo = new ActivityInfo();
    resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
    resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName();
    resolverInfo.activityInfo.name = ListActivity.class.getName();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    when(item.getUrl()).thenReturn("http://example.com/file.pdf");
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getUrl())), resolverInfo);

    WebView webView = activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
    WebFragment fragment = (WebFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(WebFragment.class.getName());
    shadowWebView.getDownloadListener().onDownloadStart(item.getUrl(), "", "", "application/pdf", 0l);
    shadowWebView.getWebViewClient().onPageFinished(webView, PDF_LOADER_URL);
    verify(fragment.mFileDownloader).downloadFile(
        eq(item.getUrl()),
        eq("application/pdf"),
        any(FileDownloader.FileDownloaderCallback.class));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:23,代码来源:WebFragmentTest.java

示例8: testSelectItemOpenExternal

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@Test
public void testSelectItemOpenExternal() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_external), true)
            .commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {
        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:22,代码来源:BaseListActivityTest.java

示例9: testSelectItemStartActionView

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@Test
public void testSelectItemStartActionView() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_external), true)
            .commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {
        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:26,代码来源:BaseListActivityTest.java

示例10: testSelectItemOpenChooser

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@Test
public void testSelectItemOpenChooser() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://news.ycombinator.com/item?id=1")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://news.ycombinator.com/item?id=1")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_external), true)
            .commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {
        @Override
        public String getUrl() {
            return "http://news.ycombinator.com/item?id=1";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_CHOOSER);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:26,代码来源:BaseListActivityTest.java

示例11: addManifestActivitiesToPackageManager

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
private void addManifestActivitiesToPackageManager(AndroidManifest appManifest, Application application) {
  if (appManifest != null) {
    Map<String,ActivityData> activityDatas = appManifest.getActivityDatas();

    RobolectricPackageManager packageManager = (RobolectricPackageManager) application.getPackageManager();

    for (ActivityData data : activityDatas.values()) {
      String name = data.getName();
      String activityName = name.startsWith(".") ? appManifest.getPackageName() + name : name;
      packageManager.addResolveInfoForIntent(new Intent(activityName), new ResolveInfo());
    }
  }
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:14,代码来源:DefaultTestLifecycle.java

示例12: addImplicitIntentToPM

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
/**
 * Seems Robolectric didn't map the implicit intent, so mock them by myself.
 */
private void addImplicitIntentToPM() {
    RobolectricPackageManager rpm =
            (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();

    AndroidManifest appManifest = ShadowApplication.getInstance().getAppManifest();
    for (Map.Entry<String, ActivityData> activity : appManifest.getActivityDatas().entrySet()) {
        String activityName = activity.getKey();
        ActivityData activityData = activity.getValue();
        if (activityData.getTargetActivity() != null) {
            activityName = activityData.getTargetActivityName();
        }

        ApplicationInfo applicationInfo = new ApplicationInfo();
        applicationInfo.packageName = RuntimeEnvironment.application.getPackageName();
        ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.resolvePackageName = RuntimeEnvironment.application.getPackageName();
        resolveInfo.activityInfo = new ActivityInfo();
        resolveInfo.activityInfo.applicationInfo = applicationInfo;
        resolveInfo.activityInfo.name = activityName;

        for (IntentFilterData intentFilterData : activityData.getIntentFilters()) {
            for (String intentFilterAction : intentFilterData.getActions()) {
                Intent i = new Intent(intentFilterAction);
                i.setPackage(RuntimeEnvironment.application.getPackageName());
                rpm.addResolveInfoForIntent(i, resolveInfo);
            }
        }
    }
}
 
开发者ID:HunkD,项目名称:Awwl,代码行数:33,代码来源:NBAbstractTest.java

示例13: addResolver

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
public static void addResolver(Intent intent) {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent( intent,
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:7,代码来源:TestApplication.java

示例14: testOptionExternal

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public String getId() {
            return "1";
        }
    });
    controller.withIntent(intent).create().start().resume();

    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();

    // open article
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_article));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);

    // open item
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:60,代码来源:ItemActivityTest.java

示例15: registerServiceWithPackageManager

import org.robolectric.res.builder.RobolectricPackageManager; //导入方法依赖的package包/类
private Context registerServiceWithPackageManager() {
    Context context = Robolectric.application;
    RobolectricPackageManager pm = (RobolectricPackageManager) context.getPackageManager();
    pm.addResolveInfoForIntent(IabHelper.BIND_BILLING_SERVICE, new ResolveInfo());
    return context;
}
 
开发者ID:jberkel,项目名称:pay-me,代码行数:7,代码来源:IabHelperTest.java


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