如何以编程方式创建

如何以编程方式创建

本文介绍了如何以编程方式创建/禁用意图过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android清单中,我有三个活动和三个针对他们的意图过滤器.

I have three activity and three Intent Filters for them in the Android Manifest.

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".firstActivity"
        android:theme="@style/AppTheme"
        android:label="@string/first">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
   </activity>
    <activity
        android:name=".secondActivity"
        android:theme="@style/AppTheme"
        android:label="@string/second">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
   </activity>
   <activity
        android:name=".thirdActivity"
        android:theme="@style/AppTheme"
        android:label="@string/third">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
   </activity ></application>

如何根据某些选项以编程方式禁用意图过滤器?或者如何在代码中创建新的意图过滤器?

How can I disable the intent filters programmatically depending on some options? Or how can I create new intent filters in code?

谢谢.

推荐答案

您不能以编程方式启用,禁用或创建<intent-filter>.

You can neither enable, disable, or create <intent-filter>s programmatically.

但是,在您的情况下,每个组件只有一个<intent-filter>.在这种情况下,您可以通过PackageManagersetComponentEnabledSetting()以编程方式启用和禁用 component .就您而言,启用或禁用活动与启用或禁用其<intent-filter>具有相同的基本效果.

However, in your case, you only have one <intent-filter> per component. In that case, you can enable and disable the component programmatically, via PackageManager and setComponentEnabledSetting(). In your case, enabling or disabling the activity would have the same basic effect as enabling or disabling its <intent-filter>.

这篇关于如何以编程方式创建/禁用意图过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:40