Back to project page ExpertAndroid.
The source code is released under:
MIT License
If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.iuriio.demos.expertandroid.ch11searchprovider; /*from w ww .jav a2 s. c o m*/ import android.app.Activity; import android.app.SearchManager; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.SearchRecentSuggestions; import android.util.Log; import android.widget.TextView; /** * Created by iuriio on 10/27/13. */ public class SearchActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_search_results); this.setDefaultKeyMode(Activity.DEFAULT_KEYS_SEARCH_LOCAL); final Intent queryIntent = this.getIntent(); final String queryAction = queryIntent.getAction(); if (Intent.ACTION_SEARCH.equals(queryAction)) { Log.d(this.getClass().getSimpleName(), "New intent for search"); this.doSearchQuery(queryIntent); } else if (Intent.ACTION_VIEW.equals(queryAction)) { this.doView(queryIntent); } } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); final String queryAction = intent.getAction(); if (Intent.ACTION_SEARCH.equals(queryAction)) { this.doSearchQuery(intent); } else if (Intent.ACTION_VIEW.equals(queryAction)) { this.doView(intent); } } private void doSearchQuery(Intent queryIntent) { final String queryString = queryIntent.getStringExtra(SearchManager.QUERY); TextView tw = (TextView) this.findViewById(R.id.text1); if (tw != null) { tw.setText(queryString); } SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SimpleSuggestionProvider.AUTHORITY, SimpleSuggestionProvider.MODE); String helpfulHint = "SSSP"; suggestions.saveRecentQuery(queryString, helpfulHint); } private void doView(Intent queryIntent) { Uri uri = queryIntent.getData(); String action = queryIntent.getAction(); Intent i = new Intent(action); i.setData(uri); this.startActivity(i); this.finish(); } }