Android LAN Search

I am trying to implement local search in my activity. I added the appropriate intent filter and metadata tag to the manifest file, but if I click the Search button, it will launch the standard Android search window. What is my problem?

Manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nixsolutions.invertigation.android.dataprovider" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <provider android:name="NoteProvider" android:authorities="com.nixsolutions.investigation.android.NoteProvider"> </provider> <activity android:name="NotesList"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application> <uses-sdk android:minSdkVersion="7" /> </manifest> 

searchable.xml:

 <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="Custom search" android:hint="Custom hint" android:searchMode="showSearchLabelAsBadge" /> 
+2
source share
1 answer

I think you also need a flag marked (at the application level) as the one that offers the search, via:

 <meta-data android:name="android.app.default_searchable" android:value=".LoremSearch" /> 

(substituting the correct value for android:value )

eg:.

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:allowBackup="true" > <meta-data android:name="android.app.default_searchable" android:value=".MySearchActivity" /> <activity android:name=".MySearchActivity"> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </activity> 

The method that you specified for only one action includes only a search within this action. Only adding a metadata tag at the application level allows you to search for all actions.

See here for a complete search project.

+1
source

Source: https://habr.com/ru/post/886212/


All Articles