- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望我的应用能够处理以下自定义 url myscheme://product?id=123
。这按预期工作。但是,以下 url 也得到处理 myscheme://product/something/else?id=123
如何防止第二个 url 被应用程序处理?
我设置了处理深层链接的 Intent 过滤器,如下面的 list
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="myscheme"/>
<data android:host="product"/>
<data android:pathPattern=".*"/>
</intent-filter>
我刚开始玩深度链接,所以非常感谢任何帮助!
最佳答案
尝试将 .* 替换为 .product?* 这应该使过滤器仅与产品查询字符串对齐,而不是产品 url 路径 (/product/something/else?id)
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="myscheme"/>
<data android:host="product"/>
<data android:pathPattern=".product?*"/>
另一种选择是创建两个 Intent 过滤器,并将它们按接收 Intent 的顺序排列:
Intent 1: product/something/else
Intent 2: product?id=1
更新:这里的关键是使用 getData() 而不是 get extras()。学会了艰难的方式:)
@Override
public void onNewIntent(Intent i) {
super.onNewIntent(i);
Bundle b = i.getExtras();
if (i != null && i.getData() != null) {
try {
Uri data = i.getData();
Map<String, String> a = splitQuery(data);
if (a.containsKey("Product") && a.containsKey("SOMETHINGELSE")){
//todo:something that takes care of something else:
}else if (a.containsKey("Product")){
mItemNumber = a.get("ID");
setUpFragmentForItem(mItemNumber);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
将 URI 分成多个段:
public static Map<String, String> splitQuery(Uri url) throws UnsupportedEncodingException {
try {
Map<String, String> query_pairs = new LinkedHashMap<String, String>();
String query = url.getQuery();
String[] pairs = query.split("/");
for (String pair : pairs) {
int idx = pair.indexOf("=");
query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
}
return query_pairs;
} catch (Exception e) {
throw new UnsupportedEncodingException(e.getMessage());
}
}
更新:发现一个做同样事情的库,值得一提,还没有用过,但我可以试一试: https://android-arsenal.com/details/1/2072
关于android - 自定义方案的 Intent-filter pathPattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36744500/
我需要为名为 myfile.ext 的单个文件定义 IntentFilter。目前我的 list 看起来像:
我找到了很多方法来设置 pathPatterns 以应用于某些目录或文件。我需要从一般模式中排除一个目录。 我有一个带有 pathPattern="/.*" 的 InstantApp intent-f
在我的应用程序中,我试图让它在有人单击浏览器上的链接时打开一个 Activity 。我正在使用这个数据 block ,但它不起作用。 例如,当我点击 www.test.com 时,它打开了应用程序,
我正在尝试制作类似 downloadmanager 的东西,但我在使用 intent-filters 时遇到了麻烦。我用于捕获文件下载 Intent 的 Intent 过滤器是这样的:
我希望我的应用能够处理以下自定义 url myscheme://product?id=123。这按预期工作。但是,以下 url 也得到处理 myscheme://product/something/e
因此,我当前用于更新对象的服务遵循以下 URL 的格式 http://www.baseurl.com/servicemethodAddObject/transactionId?clientTime=c
在我的应用程序中,我想处理使用以下模式的链接: scheme://host/folder1/folder2/folder3/folder4/article 我使用以下命令让它暂时工作:
我正在向我的 android 应用程序添加一个 intent 过滤器,我希望它能够捕获发送到 http://www.somedomain.com/[numericValue] 的请求。如果路径是数字,
我正在尝试让 Android 深层链接仅适用于特定的 url,例如: https://books.com/book/nice-title-of-a-book https://books.com/boo
我希望我的应用程序继续一些网络链接。我在 list 中为此添加了 intent-filter。它看起来像这样:
我正在使用下面的 Intent 过滤器将 Activity 与"file"方案的三种自定义扩展名相关联:.smmx、.smmstyle 和 .mm
我已经阅读了很多关于此的其他 SO - 特别是对这个问题的高度投票回答:Android intent filter for a particular file extension? 我的场景比较简单—
我们有一个 android 应用程序可以打开某些类型的文件。我已经在 AndroidManifest.xml 文件中为每个人声明了一个 Intent 过滤器(示例扩展名:ext):
不确定这是否可能,但希望有人有解决方案。 我试图让我的 Android 应用拦截 mydomain.com/abc 形式的 url,但不是 mydomain.com/mp3/id 是否有可能使用 pa
Documentation states可以在 pathPattern 中使用通配符。 A period followed by an asterisk (".*") matches any sequ
我想为这两个 http url 创建深层链接 https://sample-app-123.appspot.com/backoffice/#/user_reset_password?email=abc
我已阅读有关在 android studio 3.0 中创建深层链接和使用应用程序链接服务的文档。它非常简单易懂,但是当我的 URL 没有前缀路径时我遇到了一点问题。示例: https://examp
我正在尝试制定一个过滤某些特定网址的 Intent 。我要捕获的网址是: > http://host.com/app > http://host.com/app/ > http://host.com/
我是一名优秀的程序员,十分优秀!