在Android 10上,可以使用以下代码示例来创建两个相似的意图过滤器:
IntentFilter intentFilter1 = new IntentFilter();
intentFilter1.addAction(Intent.ACTION_SEND);
intentFilter1.addCategory(Intent.CATEGORY_DEFAULT);
intentFilter1.setType("text/plain");
上述代码创建了一个意图过滤器,它用于捕获发送文本数据的意图。它将过滤那些具有ACTION_SEND
操作、CATEGORY_DEFAULT
类别和MIME类型为text/plain
的意图。
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(Intent.ACTION_VIEW);
intentFilter2.addCategory(Intent.CATEGORY_BROWSABLE);
intentFilter2.addDataScheme("http");
上述代码创建了另一个意图过滤器,它用于捕获浏览器打开HTTP链接的意图。它将过滤那些具有ACTION_VIEW
操作、CATEGORY_BROWSABLE
类别和scheme
为http
的意图。
请注意,在将这些意图过滤器应用于您的应用程序时,您需要在清单文件中声明相关的活动和意图过滤器。