File Search
File search provider plugins need to extend the FileProvider
class:
class MyFileSearchPlugin : FileProvider(
SearchPluginConfig()
)
In the super constructor call, pass a SearchPluginConfig
object.
Plugin config
Search plugins have the following configuration properties:
storageStrategy
: Describes how the launcher should store a search result in its internal database. This is relevant when a user pins a search result to favorites, or when they assign a tag or custom label. In these situations, the launcher needs to be able to restore the search result from its database. There are two different strategies:StorageStrategy.StoreReference
: The launcher only stores the ID of the search result, and the plugin that created it. To restore a result, the plugin is queried again. This strategy allows the plugin provider to update a search result at a later point in time. However, plugins that use this strategy must guarantee that a search result can be restored in a timely manner. In particular, the plugin provider must be able to restore a search result without any network requests.StorageStrategy.StoreCopy
(default): The launcher stores all relevant information about this search result in its own internal database. The result can be restored without querying the plugin again. This strategy is very easy to implement. The downside is, that results cannot be updated at a later point in time.
Search files
To implement file search, override
suspend fun search(query: String, allowNetwork: Boolean): List<File>
query
is the search termallowNetwork
is a flag that indicates whether the user has enabled online search for this query. Plugins are generally advised to respect this request. This flag exists mainly for privacy reasons: the majority of searches target offline results (like apps, or contacts). Sending every single search request to external servers is overkill and can be a privacy issue. (Besides, it's not very nice to overload servers with unnecessary requests.) To reduce the amount of data that is leaked to external servers, users can control, whether a search should include online results or not.
search
returns a list of File
s. The list can be empty if no results were found.
The File
object
A File
has the following properties:
id
: A unique and stable identifier for this file. This is used to track usage stats so if two files are identical, they must have the same ID, and if they are different, they need to have different IDs.uri
: A URI that is used to open the file.displayName
: The name that is shown to the usermimeType
: The MIME type of the file. This is only used for informational purposes, i.e. to determine the icon.size
: The file size in bytes.path
: The file path. This is shown for informational purposes. It is not used to read or open the file.isDirectory
: Whether the file is a folder. If true, a folder icon is shown.thumbnailUri
: An optional URI to a file thumbnail. Supported schemes are:content
,file
,android.resource
,http
, andhttps
. If this is acontent
URI, make sure that the launcher has the permissions to access it.owner
: The name of the owner of the file. This is mainly relevant for files that are stored in a cloud drive and are not owned by the user themselves, but shared with them.metadata
: Additional file metadata.
Get a file
If you have set config.storageStrategy
to StorageStrategy.StoreReference
, you must override
suspend fun get(id: String): File?
This method is used to lookup a file by its id
. If the file is no longer available, it should return null
. In this case, the launcher will remove it from its database.
Plugin state
Some plugins need to be configured before they can be used. For example, users might need to connect an account, or provide an API key.
If your plugin has such requirements, you can override
suspend fun getPluginState(): PluginState
This method can either return PluginState.Ready
, or PluginState.SetupRequired
.
PluginState.Ready
can have a statustext
to describe what the plugin does in its current configuration. For example "Search {username}'s files on {service}". This overrides the plugin's description.PluginState.SetupRequired
needs to have asetupActivity
Intent that starts the setup. You can also provide amessage
to describe what kind of setup needs to be performed. For example "Sign in with {service} to search files on {service}"
IMPORTANT
This method is only meant to provide hints to the launcher's user interface. You should not rely on it as a safeguard for your other plugin methods. There is still a chance that your other plugin methods are called regardless of the return value of this method. Make sure to check your requirements in the other plugin methods as well.