机器人通过捆绑搜索机器人

2023-09-04 09:25:35 作者:月下弄人醉

你好,我是采用了android 3.0 搜索小工具(而不是搜索模式),问题是我需要传递一些参数与搜索词。

安卓并没有叫任何一个

  searchManager.setOnDismissListener(新OnDismissListener(){

            @覆盖
            公共无效onDismiss(){
                // TODO自动生成方法存根
                Log.v(MyApp.TAG,关于解聘搜索);

            }
        });

        sea​​rchManager.setOnCancelListener(新OnCancelListener(){

            @覆盖
            公共无效OnCancel的(){
                // TODO自动生成方法存根
                Log.v(MyApp.TAG,关于解聘取消);

            }
        });

@覆盖
    公共布尔onSearchRequested(){
        捆绑应用程序数据=新包();
        appData.putLong(listino_id,this.listino_id);
        this.startSearch(NULL,真实,应用程序数据,FALSE);
        返回true;
        //返回super.onSearchRequested();
    }
 

我需要我的活动为不可以是singleOnTop, 这里是我的Andr​​oidManifest.xml

 <活动机器人:名称=机器人activity.ListinoProdottiActivity。:windowSoftInputMode =stateHidden>


             <  - !接收搜索请求。 - >
            <意向滤光器>
                <作用机器人:名称=android.intent.action.SEARCH/>
                <! - 任何一类需要,因为其目的将指定该类组件 - >
            &所述; /意图滤光器>

                   <! - 使基地活动来发送搜索本身 - >
            <元数据的android:NAME =android.app.default_searchable
              activity.ListinoProdottiActivity:机器人值= />


            <! - 指向搜索的元数据。 - >
            <元数据的android:NAME =android.app.searchable
                       机器人:资源=@ XML /搜索/>

        < /活性GT;
 

下面是我的searchable.xml

 < XML版本=1.0编码=UTF-8&GT?;
<可搜索的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:标签=@字符串/ APP_NAME
     />
 
索尼机器人亮相科学探索展

解决方案

传中搜索窗口小部件包数据:

布局/ main.xml中

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    < TextView的Andr​​oid的:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT机器人:文本=@字符串/你好/>
    <按钮机器人:ID =@ + ID /按钮机器人:文本=测试
        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
 

布局/ searchable.xml

 < XML版本=1.0编码=UTF-8&GT?;
<可搜索的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:标签=@字符串/ search_label
    机器人:提示=@字符串/ search_hint
    机器人:搜索模式=showSearchLabelAsBadge
    机器人:voiceSearchMode =showVoiceSearchButton | launchRecognizer
    机器人:voiceLanguageModel =free_form
    机器人:voicePromptText =@字符串/ search_invoke
    机器人:?searchSuggestSelection =
/>
 

价值/ strings.xml中

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
<字符串名称=你好>的Hello World,SearchTest<!/串>
<字符串名称=APP_NAME> Searchtest< /串>
<字符串名称=search_label>搜索测试与LT; /串>
<字符串名称=search_hint> 1234< /串>
<字符串名称=search_invoke> 234< /串>
<字符串名称=search_query_results> 544545< /串>
< /资源>
 

AndroidManifest.xml中

 <应用
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME>
        <活动
            机器人:标签=@字符串/ APP_NAME
            机器人:名称=SearchWidgetExampleTest。>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>

                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
            <元数据的android:NAME =android.app.default_searchable
                       机器人:值=。ResultActivty/>
        < /活性GT;

         <活动机器人:名称=。ResultActivty
                  机器人:标签=@字符串/ search_query_results>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.SAMPLE_ code/>
            &所述; /意图滤光器>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.SEARCH/>
                <类机器人:名称=android.intent.category.DEFAULT/>
            &所述; /意图滤光器>
            <元数据的android:NAME =android.app.searchable
                       机器人:资源=@布局/搜索/>
        < /活性GT;
    < /用途>
 

ResultActivty.java

 包org.imranandroid.TestSearchexmp;
进口android.app.Activity;
进口android.app.SearchManager;
进口android.os.Bundle;
进口android.widget.Toast;

公共类ResultActivty延伸活动{
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        捆捆绑= getIntent()getBundleExtra(SearchManager.APP_DATA)。
        长ttdata = bundled.getLong(listino_id);
        Toast.makeText(这一点,ttdata.toString(),Toast.LENGTH_SHORT).show();
    }
}
 

SearchWidgetExampleTest.java

 包org.imranandroid.TestSearchexmp;
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;

公共类SearchWidgetExampleTest延伸活动{
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        按钮按钮1 =(按钮)findViewById(R.id.button);
        button1.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                onSearchRequested();
            }
        });
    }
    @覆盖
    公共布尔onSearchRequested(){
        捆绑appDataBundle =新包();
        appDataBundle.putLong(listino_id,4434724724L);
        开始搜索(伊姆兰,假的,appDataBundle,假);
        返回true;
    }
}
 

Happly编码!!! 的

Hello i am using android 3.0 search widget(not the search mode), the problem is i need to pass some parameters along with the search word.

Android isn't calling any of these

    searchManager.setOnDismissListener( new OnDismissListener() {

            @Override
            public void onDismiss() {
                // TODO Auto-generated method stub
                Log.v(MyApp.TAG, "on dismiss search");

            }
        });

        searchManager.setOnCancelListener( new OnCancelListener() {

            @Override
            public void onCancel() {
                // TODO Auto-generated method stub
                Log.v(MyApp.TAG, "on dismiss cancel");

            }
        });

@Override
    public boolean onSearchRequested() {
        Bundle appData = new Bundle();
        appData.putLong("listino_id", this.listino_id);
        this.startSearch(null, true, appData, false);
        return true;
        // return super.onSearchRequested();
    }

I need my activity to NOT be singleOnTop, here is my AndroidManifest.xml

 <activity android:name=".activity.ListinoProdottiActivity" android:windowSoftInputMode="stateHidden">


             <!-- Receives the search request. -->
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <!-- No category needed, because the Intent will specify this class component-->
            </intent-filter>

                   <!-- enable the base activity to send searches to itself -->
            <meta-data android:name="android.app.default_searchable"
              android:value=".activity.ListinoProdottiActivity" />


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

        </activity>

Here is my searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
     />

解决方案

pass data with bundle in Search Widget:

layout/main.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
    <Button android:id="@+id/button" android:text="test"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>

layout/searchable.xml :

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="free_form"
    android:voicePromptText="@string/search_invoke"
    android:searchSuggestSelection=" ? "
/>

values/strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, SearchTest!</string>
<string name="app_name">Searchtest</string>
<string name="search_label">Search Test</string>
<string name="search_hint">1234</string>
<string name="search_invoke">234</string>
<string name="search_query_results">544545</string>
</resources>

AndroidManifest.xml :

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SearchWidgetExampleTest" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="android.app.default_searchable"
                       android:value=".ResultActivty" />
        </activity>

         <activity android:name=".ResultActivty"
                  android:label="@string/search_query_results">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </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="@layout/searchable" />
        </activity>
    </application>

ResultActivty.java:

package org.imranandroid.TestSearchexmp;
import android.app.Activity;
import android.app.SearchManager;
import android.os.Bundle;
import android.widget.Toast;

public class ResultActivty extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bundle bundled= getIntent().getBundleExtra(SearchManager.APP_DATA);
        Long ttdata=bundled.getLong("listino_id");
        Toast.makeText(this, ttdata.toString(), Toast.LENGTH_SHORT).show();
    }
}

SearchWidgetExampleTest.java :

package org.imranandroid.TestSearchexmp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SearchWidgetExampleTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button1 = (Button) findViewById(R.id.button);
        button1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSearchRequested();
            }
        });
    }
    @Override
    public boolean onSearchRequested() {
        Bundle appDataBundle = new Bundle();
        appDataBundle.putLong("listino_id", 4434724724L);
        startSearch("imran", false, appDataBundle, false);
        return true;
    }
}

Happly Coding!!!

 
精彩推荐
图片推荐