2015-06-22 79 views
0

我試圖按照android documentation執行''使用特定應用程序'功能進行搜索。但我無法得到它的工作。這是我的查詢'確定谷歌,在helloapp搜索xyz'無法執行Google API'使用特定應用程序進行搜索'

以下是我的實施。我已經添加了不需要的元數據,但沒有它也無法工作。

實施

清單

<activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <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=".SearchableActivity" /> 
    </activity> 
    <activity 
     android:name=".SearchableActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
     </intent-filter> 

     <meta-data 
      android:name="android.app.searchable" 
      android:value=".SearchableActivity" /> 

    </activity> 

檢索活動

public class SearchableActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.searchlayout); 

     Intent intent = getIntent(); 
     if(SearchIntents.ACTION_SEARCH.equals(intent.getAction())){ 
      String query = intent.getStringExtra(SearchManager.QUERY); 
      Toast.makeText(getApplicationContext(), query, Toast.LENGTH_LONG).show(); 
     } 

    } 

} 
+0

我只是在http://stackoverflow.com/questions/26982653/how-to-integrate-searchable-activity-with-ok-google-閱讀效仿這一語音搜索,該應用程序需要發佈到應用程序商店才能正常工作。 –

回答

2

從這個post想通了,該應用程序必須首先公佈了泛函工作。但是,我們可以用下面的adb shell命令

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query 'search for xyz on..' packagename 
+0

只是添加它似乎也必須公開可用。 –

相關問題