问题
Background
For some time, as a user, I've noticed that on some apps I can perform common operations on partial texts, as such:
This is called "smart text selection" (video here), and it has being around from Android O, as shown here.
The problem
Recently Google has shown how to make your app show the actions within itself (meaning inside its TextView). This is called "Smart-Linkify" and the video about it can be found here. It shows there how to show the actions:
What I can't find is how to do the opposite. Meaning how to offer my own actions to other apps.
For example, I could make a dialer app that can handle phone numbers by either dialing them or search the phone number.
What I've found
In the past, I've asked about a very similar thing, of Android M, here. There is also a nice tutorial about it, here. However, this is about a general text, without a type of when to trigger, meaning it will always be shown.
I've found very few mentions about this feature. The only sample I've found is here, but I can't build it for some reason, and it's not even about providing the actions. It's about how to show the actions.
I've found a Github repository of the Android dialer, here. It also offers an action of "call" for phone numbers. After playing around with the manifest, I've found that this part is responsible for offering this action:
<intent-filter > <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.DIAL" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tel" /> </intent-filter>
If I remove this part, I don't see the action of "call" for this app anymore (till I re-add it).
Sadly, if I change the "DIAL" action to "SEARCH", it doesn't show up.
The good news are that I can see the action if I add this part to a new project.
The questions
- This is from Android O and above, right? What would happen on Android M or N, when I implement this feature?
- How can I offer my own app actions to other apps? So far I've found how to do a general text handling, and dialing. But how can I provide others, such as search of phone number?
- Can I customize the text that's shown for the actions? I've noticed that if I change the label for the "PROCESS_TEXT" action, it does change, but I can't see how to do it for other actions.
- Can I customize what will trigger the action? For example a specific regular expression to match ? I've found only phone numbers so far. What are the various things I can use for this filtering?
回答1:
OK, seeing that I fail to do it, over and over, no matter what I try, I think the answer is that it's just not supported.
The reason is that Google probably collects various actions that developers request around the world, and use the list for the device. More information here. To quote from there:
Get your app discovered in more places across multiple Google and Android surfaces. Your Actions can appear in the Android launcher, Smart Text Selection, the Google Search app, the Google Assistant, and the Play Store.
Here's a list of existing special Intents actions that developers can use.
It doesn't have a special one for phone number searching, but it has some other special actions instead.
In order to request more actions to be available, developers can request it here.
I hope this will be available forever, because I don't think a lot of developers even know about this.
来源:https://stackoverflow.com/questions/50423546/how-to-offer-actions-of-my-app-to-other-apps-via-smart-linkify-aka-smart-text