选择性地使一个活动别名在清单与Android:启用=" @布尔/平板电脑"或QUOT; @布尔/手机"支持的? [英] Is selectively enabling an activity-alias in the manifest with android:enabled="@bool/tablet" or "@bool/phone" supported?

查看:218
本文介绍了选择性地使一个活动别名在清单与Android:启用=" @布尔/平板电脑"或QUOT; @布尔/手机"支持的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要避免一些平板电脑/电话连线,我想我的应用程序通过一个活动别名问题本身的意图,使舱单系统,它提供给主要活动(片剂),或一个新的活动(用于手机)。

To avoid some Tablet/Phone wiring, I want my app to issue itself an intent via an activity-alias, and make the manifest system deliver it to the main activity (for tablet) or a new activity (for phone).

如果我有这在我的清单:

If I have this in my manifest:

<activity-alias android:name="my.app.WebContent"
              android:targetActivity="my.app.activities.Home"/>

就万事大吉,以及

then all is well, and

Intent {
    act=android.intent.action.VIEW dat=http://www.app.my/url
    cmp=my.app/.WebContent (has extras) }

如预期交付。

但是,如果我有这个在我的清单:

If, however, I have this in my manifest:

<activity-alias android:name="my.app.WebContent"
              android:enabled="@bool/has_one_pane"
              android:targetActivity="my.app.activities.WebContent"/>
<activity-alias android:name="my.app.WebContent"
              android:enabled="@bool/has_two_panes"
              android:targetActivity="my.app.activities.Home"/>

这个价值观/ res.xml

with this in values/res.xml

<resources>
    <bool name="has_two_panes">false</bool>
    <bool name="has_one_pane">true</bool>
</resources>

而这价值观大/ res.xml和价值观sw600dp / res.xml:

and this in values-large/res.xml, and values-sw600dp/res.xml:

<resources>
    <item type="layout" name="content_frame">@layout/activity_item_twopane</item>
    <bool name="has_two_panes">true</bool>
    <bool name="has_one_pane">false</bool>
</resources>

然后我的code过滤掉的意图为无法送达根据PackageManager.resolveActivity()。

then my code filters out the intent as 'undeliverable' according to PackageManager.resolveActivity().

似乎值/ res.xml覆盖价值观什么/ res.xml,即使价值观大是应该重写值/ res.xml的大屏幕显示器。

It seems that values/res.xml overrides values-anything/res.xml, even though values-large is supposed to override values/res.xml for large displays.

这是在Android中的一个bug,或者有我误解了这个应该怎么做?

Is this a bug in Android, or have I misunderstood how this should be done?

推荐答案

没有,它不支持,因为事情像屏幕宽度(RES /布局w600dp)可以通过方向改变,但谷歌并没有明显地注意到,最小宽度 (RES /布局sw600dp)不受这一点。见<一href=\"http://stackoverflow.com/questions/12513668/fragment-orientation-change-better-test-than-for-landscape\">Fragment取向的转变 - 比景观更好的测试

No, it's not supported because things like screen width (res/layout-w600dp) can change by orientation but Google didn't apparently notice that 'smallest width' (res/layout-sw600dp) isn't affected by that. See Fragment Orientation Change - Better Test than for Landscape

请注意过的变通方法<建议href=\"http://stackoverflow.com/questions/13202805/how-to-specify-activities-that-are-only-for-phones-or-tablets-on-android/13202806#13202806\">How指定只在Android手机或平板电脑不适合竞争与LT工作活动,活动的别名&GT;因为你不能建立一个组件名的名字命名的别名之间唯一的选择。

Note too that the workaround suggested in How to specify Activities that are only for phones or tablets on Android doesn't work for competing <activity-alias> because you cannot construct a ComponentName to uniquely select between aliases of the name name.

(除非它可能只禁用针对性的活动之一,并依靠在清单订购的替代品之间的交换,但具有脆弱性的问题。)

(Unless it's possible to disable only one of the targeted activities and rely on ordering within the manifest to swap between the alternatives, but that has fragility issues.)

这篇关于选择性地使一个活动别名在清单与Android:启用=&QUOT; @布尔/平板电脑&QUOT;或QUOT; @布尔/手机&QUOT;支持的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆