gpt4 book ai didi

android - Intent.ACTION_VIEW 在可搜索中不起作用

转载 作者:行者123 更新时间:2023-11-30 03:06:14 25 4
gpt4 key购买 nike

我正在尝试在用户单击搜索建议时设置 Intent.ACTION_VIEW。它仍然执行 ACTION_SEARCH Intent ,因此它在建议框中搜索提供的信息,但我希望它将它传递给已经显示单击对象的 Activity。我不使用 SearchActivity 及其方法(onNewIntent 等),我只使用 Activity,它显示结果列表 - 它设置为 _default_searchable。

但是如果我需要在选择建议项时将其传递给不同的 Activity ,我该怎么办?

我在 Manifest 的第二个 Activity 中将 android:searchSuggestIntentAction="android.intent.action.VIEW" 和 intent-filter 设置为 intent.VIEW 但它不起作用

你知道怎么做吗?

searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:searchSuggestAuthority="com.example.animalist.SuggestionProvider"
android:searchSuggestSelection=" ?"
android:searchSuggestIntentAction="android.intent.action.VIEW"


/>

list

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<provider
android:authorities="com.example.animalist.SuggestionProvider"
android:name=".SuggestionProvider" >
</provider>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity"/>
<activity
android:name="com.example.animalist.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity"/>

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<activity
android:name="com.example.animalist.MoreActivity"
android:label="@string/title_activity_more"
android:launchMode="singleTop"
android:parentActivityName="com.example.animalist.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.animalist.MainActivity" />

<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>


</activity>

<activity
android:name="com.example.animalist.SearchActivity"
android:label="@string/title_activity_search"
android:launchMode="singleTop"
android:parentActivityName="com.example.animalist.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.animalist.MainActivity" />


<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />

</activity>

</application>

提供者

public class SuggestionProvider extends SearchRecentSuggestionsProvider {
private static final String TAG = "SuggestionProvider";

private static final int SEARCH_SUGGESTIONS = 1;

private static final UriMatcher sURLMatcher = new UriMatcher(
UriMatcher.NO_MATCH);

static {
sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY,
SEARCH_SUGGESTIONS);
sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
SEARCH_SUGGESTIONS);
}

private static final String[] COLUMNS = new String[] {
"_id",
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
SearchManager.SUGGEST_COLUMN_QUERY,
SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA
};

public SuggestionProvider() {
}

@Override
public boolean onCreate() {
return true;
}

@Override
public Cursor query(Uri url, String[] projectionIn, String selection,
String[] selectionArgs, String sort) {
int match = sURLMatcher.match(url);
switch (match) {
case SEARCH_SUGGESTIONS:
String query = url.getLastPathSegment();
MatrixCursor cursor = new MatrixCursor(COLUMNS);

ParseQuery<Animal> squery = ParseQuery.getQuery(Animal.class);
try {

List<Animal> results = squery.find();
for (Animal animal : results) {
addRow(cursor, animal.getAnimal());
} }catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return cursor;}
return null;
}





private void addRow(MatrixCursor cursor, String string) {
long id = cursor.getCount();
cursor .newRow().add(id).add(string).add(Intent.ACTION_SEARCH).add(string);
}

@Override
public String getType(Uri url) {
int match = sURLMatcher.match(url);
switch (match) {
case SEARCH_SUGGESTIONS:
return SearchManager.SUGGEST_MIME_TYPE;
default:
throw new IllegalArgumentException("Unknown URL: " + url);
}
}

@Override
public int update(Uri url, ContentValues values, String where, String[] whereArgs) {
throw new UnsupportedOperationException("update not supported");
}

@Override
public Uri insert(Uri url, ContentValues initialValues) {
throw new UnsupportedOperationException("insert not supported");
}

@Override
public int delete(Uri url, String where, String[] whereArgs) {
throw new UnsupportedOperationException("delete not supported");
}
}

在此先感谢您的帮助

最佳答案

虽然这不是一个很好的方法,但我之前通过创建一个处理 VIEW 和 SEARCH 两个 Intent 的透明 Activity 解决了这个问题。

从这个 Activity 中,您可以启动将处理任一情况的 Activity 并完成透明 Activity ,传递搜索参数。

关于android - Intent.ACTION_VIEW 在可搜索中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21766765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com