Skip to content

Commit c6bb481

Browse files
committed
部分修改,去掉英文
部分修改,去掉英文
1 parent 2382000 commit c6bb481

File tree

1 file changed

+6
-50
lines changed

1 file changed

+6
-50
lines changed
Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Android M中Intent的解析
1+
Android 6.0中Intent的解析
22
---
33

44
> * 原文链接 : [Intent Resolving in Android M](https://medium.com/google-developer-experts/intent-resolving-in-android-m-c17d39d27048#.n23z2g14e)
@@ -8,57 +8,33 @@ Android M中Intent的解析
88
* 校对者: [这里校对者的github用户名](github链接)
99
* 状态 : 未完成
1010

11-
Warning! Resolving of “Implicit Intent”s in Android Marshmallow is not working as the same as before. This may break your app’s behavior.
12-
13-
注意了!在Android Marshmallow中,“隐式Intent”的解析不能像之前版本那样正常工作了。这很有可能导致你的app不能正常使用。
14-
15-
Let me explain the expected behavior and why is not working:
16-
I have recently been working on a small open source project called “Open Link With”. It will hopefully be in the Play Store soon.
11+
注意了!在Android 6.0中,“隐式Intent”的解析不能像之前版本那样正常工作了。这很有可能导致你的app不能正常使用。
1712

1813
现在让我解释一下这个意料之中的问题以及为什么它不能正常使用:
1914
最近,我正在开发一个小的开源项目,叫做“Open Link With”。希望不久后它能够在应用市场上架。
2015

21-
My app gives you the ability to switch between other apps. When you share a link with me, I basically grab the link and query all the Activity’s that can handle that link. And finally I mimic the system dialog and let you switch apps.
22-
2316
我的这个app能够让你在其他app之间随意切换。当你给我分享一个链接的时候,我基本上可以根据这个链接查询出所有可以处理这个链接的Activity。然后我会模拟一个系统对话框让你切换app。
2417

2518
![从已经打开的youtube的web页面切换到youtube应用](https://cdn-images-1.medium.com/max/1600/1*rW8I8aCpJ2q8fnfKH_51_g.gif)
2619

27-
I was using the below method as always:
2820
我一直都是使用下面的方法:
2921

3022
```
3123
List<ResolveInfo> infos = packageManager
3224
.queryIntentActivities(intent, MATCH_DEFAULT_ONLY);
3325
```
3426

35-
It is a familiar method to almost all Android developers and I am sure that it is currently being used in lots of apps.
36-
37-
I have 2 browsers in my phone. “An Intent with Google+ URL” is expected to give a list of 3 ResolveInfo objects (Google+ app and 2 browsers).
38-
3927
这段代码几乎所有Android开发者都比较熟悉,并且我也相信大部分app都有用到这段代码。
4028

4129
我的手机里有两个浏览器。“一个URL是Google+ 的Intent”期望得到一个具有3个ResolveInfo对象的列表(Google+应用以及两个浏览器)。
4230

43-
Well, not anymore!
44-
45-
Welcome to Android Marshmallow!
46-
47-
Android Marshmallow introduced App Links. The system basically authenticates with your web-page and opens those URLs automatically using your application without asking anything to user. Or you can go to system Settings, Apps, click an app, click “Open by default” and then set “Open in this app” to use always that app.
48-
4931
好吧,并不是这样!
5032

51-
欢迎来到Android棉花糖!
52-
53-
Android棉花糖引进了应用关联。系统主要通过你的web页面来认证,并且自动使用你的app来打开这些URL,而不会向你做任何请求。或者你可以到系统设置,选择“应用程序”,然后点击一个应用,再点击“默认打开方式”,然后设置“用这个应用打开”,就可以每次都使用这个应用打开。
54-
55-
![棉花糖的应用默认设置页面](https://cdn-images-1.medium.com/max/800/1*MVZbYKhwu-7qnyGAFWuNsw.png)
56-
57-
In that case, queryIntentActivities method will give developers a list with only 1 Activity (which is Google+ in this case).
33+
欢迎来到Android 6.0!
5834

59-
Even if this is the desired behavior, this should be documented because it breaks the behavior of a public API.
35+
Android 6.0引进了应用关联。系统主要通过你的web页面来认证,并且自动使用你的app来打开这些URL,而不会向你做任何请求。或者你可以到系统设置,选择“应用程序”,然后点击一个应用,再点击“默认打开方式”,然后设置“用这个应用打开”,就可以每次都使用这个应用打开。
6036

61-
I researched a little bit and found MATCH_ALL flag. It’s documentation says that it will disable all system level filters.
37+
![Android 6.0的应用默认设置页面](https://cdn-images-1.medium.com/max/800/1*MVZbYKhwu-7qnyGAFWuNsw.png)
6238

6339
在这种情况下,queryIntentActivities方法只会给开发者返回一个只有一个Activity的列表(此例子返回的是Google+)。
6440

@@ -75,44 +51,24 @@ I researched a little bit and found MATCH_ALL flag. It’s documentation says th
7551
public static final int MATCH_ALL = 0x00020000;
7652
```
7753

78-
It didn’t do anything for me. I opened the source code (at least we have that!) and investigated the method.
79-
80-
It looks like they prioritize the domain verified applications. They did not just prioritize in their internal system, they also did it in the public API.
81-
82-
If there is a domain verified application, it does not return anything else. MATCH_ALL flag removes some system filters but only if there is no verified application.
83-
8454
这对我来说没什么用。我打开源码(至少我有源码)并开始研究这个方法。
8555

8656
它似乎优先考虑验证应用程序的域,不仅在它的内部系统,在公共API中也是如此。
8757

8858
如果有一个验证应用程序的域,它不会返回任何其他东西。MATCH_ALL标志会移除一些系统过滤器,但是仅仅是在没有验证程序的情况下。
8959

90-
I couldn’t find any way to workaround this behavior. It simply eliminates browser apps even when their IntentFilters match.
91-
92-
There is no workaround because it is an internal component (which we cannot access) and Android SDK communicates with it using IPC communication using AIDL.
93-
9460
对于这个问题,我找不到任何可变通的措施。它只是排除浏览器应用,即使他们的IntentFilters匹配。
9561

9662
之所以没有可变通的措施,是因为他是一个内部组件(我们无法访问),Android SDK通过IPC使用AIDL与它进行通信。
9763

98-
Most of the developers are using this method to find if there is at least 1 Activity to handle the implicit Intent. In most of the situations the first item in the list is the one you want anyway.
99-
10064
大部分开发者使用这个方法来判断是否至少有一个Activity来处理隐式的Intent。在大多数情况下,列表中第一项就是你想要的。
10165

102-
After spending hours to understand what’s going on and trying to find a workaround, I thought everyone should know this.
103-
104-
There are lots of behavior changes in Android M. Google actually provided a list of behavior changes. You can find it here. I am sure that just like this, there are lots of hidden behavior changes that may break applications.
105-
10666
在花了几个小时搞明白到底发生了什么之后,我尝试寻找一个我认为每个人都应该知道的解决方案。
10767

108-
在Android M中,改动的地方很多。实际上谷歌提供了一些改变清单,在清单中你能看到到底有哪些改变。我认为还有很多类似上面的一些没有在清单中列出的改变,而这些改动很有可能导致你的应用无法正常运行。
109-
110-
So beware of this, and check your situation if you use PackageManager methods.
68+
在Android 6.0中,改动的地方很多。实际上谷歌提供了一些改变清单,在清单中你能看到到底有哪些改变。我认为还有很多类似上面的一些没有在清单中列出的改变,而这些改动很有可能导致你的应用无法正常运行。
11169

11270
所以如果你使用PackageManager的方法,你一定得小心,并且认真检查。
11371

114-
Thanks to the people who proofread this article: Yağmur Dalman, Sebastiano Poggi, Salim KAYABAŞI, Hasan Keklik
115-
11672
感谢此文的校对者:[Yağmur Dalman](https://twitter.com/yagmurdalman)[ Sebastiano Poggi](https://medium.com/u/9706138c9bfb)[Salim KAYABAŞI](https://medium.com/u/73761c65c602)[Hasan Keklik](https://medium.com/u/24a0490cd588)
11773

11874

0 commit comments

Comments
 (0)