Browser.EXTRA_APPLICATION_ID在平板电脑中不起作用。您是否知道其他方法可以重用Browser.apk的选项卡?

时间:2012-03-28 06:28:10

标签: android browser android-intent

EXTRA_APPLICATION_ID似乎无法在平板电脑中使用。在我的服务意图启动浏览器时,您是否知道重复使用Browser.apk的选项卡?这与9902225直接相关。任何提示都表示赞赏。

原因:如果设备是平板电脑,则不会调用resuseTab()。

见行:

* 3-tablet) Open new tab

见行:

if (activateVoiceSearch || !BrowserActivity.isTablet(mActivity)) {

// Browser.apk源代码(Android 4.0.3_r1-6)

com.android.browser.IntentHandler

void onNewIntent(Intent intent) {
....
   /*
     * TODO: Don't allow javascript URIs
     * 0) If this is a javascript: URI, *always* open a new tab
     * 1) If this is a voice search, re-use tab for appId
     *    If there is no appId, use current tab
     * 2) If the URL is already opened, switch to that tab
     * 3-phone) Reuse tab with same appId
     * 3-tablet) Open new tab
     */
    final String appId = intent
            .getStringExtra(Browser.EXTRA_APPLICATION_ID);
    if (!TextUtils.isEmpty(urlData.mUrl) &&
            urlData.mUrl.startsWith("javascript:")) {
        // Always open javascript: URIs in new tabs
        mController.openTab(urlData);
        return;
    }
    if ((Intent.ACTION_VIEW.equals(action)
            // If a voice search has no appId, it means that it came
            // from the browser.  In that case, reuse the current tab.
            || (activateVoiceSearch && appId != null))
            && !mActivity.getPackageName().equals(appId)) {
        if (activateVoiceSearch || !BrowserActivity.isTablet(mActivity)) {
            Tab appTab = mTabControl.getTabFromAppId(appId);
            if (appTab != null) {
                mController.reuseTab(appTab, urlData);
                return;
            }
        }
        // No matching application tab, try to find a regular tab
        // with a matching url.
        Tab appTab = mTabControl.findTabWithUrl(urlData.mUrl);
        if (appTab != null) {
            // Transfer ownership
            appTab.setAppId(appId);
            if (current != appTab) {
                mController.switchToTab(appTab);
            }
            // Otherwise, we are already viewing the correct tab.
        } else {
            // if FLAG_ACTIVITY_BROUGHT_TO_FRONT flag is on, the url
            // will be opened in a new tab unless we have reached
            // MAX_TABS. Then the url will be opened in the current
            // tab. If a new tab is created, it will have "true" for
            // exit on close.
            Tab tab = mController.openTab(urlData);
            if (tab != null) {
                tab.setAppId(appId);
                if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
                    tab.setCloseOnBack(true);
                }
            }
        }

1 个答案:

答案 0 :(得分:11)

对于ICS和平板电脑设备,您需要将意图的App ID设置为浏览器的App ID。 因此,您需要使用com.android.browser代替getPackageName()