如何仅使用xml从首选项屏幕开始按包名称启动应用程序

时间:2014-08-30 08:31:14

标签: android android-xml

我正在使用首选项活动,我希望能够在不使用Java代码的情况下点击首选项来启动应用程序。

这样的事情:

  <Preference
    android:title="Tap me to start settings app"
    android:key="prefSettings"
    />

因此,当我点击它时,将打开一个包含已知包名称的新应用程序。

请注意:我希望能够在没有java代码的情况下执行此操作,仅限xml。

这可能吗?

1 个答案:

答案 0 :(得分:0)

它可能但非常有限,我无法想到任何用例,因为您不知道&#34;目标应用程序&#34; < / em>存在(至少你不能通过XML检查它)。

以下是代码:

<Preference
    android:key="my_key"
    android:summary="@string/my_summary"
    android:title="@string/my_title">
    <intent
        android:targetPackage="package.of.other.app"
        android:action="android.intent.action.MAIN"
        android:targetClass="package.of.other.app.class"
    />
</Preference>