在Android应用中实现Google搜索的例子
有一个很简单的方法在你的 Android 应用中实现 Google 搜索。在这个例子中,我们将接受用户的输入作为搜索词,我们将使用到 Intent.ACTION_WEB_SEARCH 。
GoogleSearchIntentActivity.java
package com.technotalkative.googlesearchintent;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class GoogleSearchIntentActivity extends Activity {
private EditText editTextInput;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editTextInput = (EditText) findViewById(R.id.editTextInput);
}
public void onSearchClick(View v)
{
try {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
}
}
}
main.xml
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp">
<edittext android:id="@+id/editTextInput" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter search text">
<requestfocus>
</requestfocus></edittext>
<button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search" android:layout_gravity="center" android:onclick="onSearchClick" android:layout_margintop="10dp">
</button></linearlayout>
注意:不要忘了在 AndroidManifest.xml 文件中添加 INTERNET 权限。
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
输出:
在Android应用中实现Google搜索的例子的更多相关文章
- 【Unity与Android】02-在Unity导出的Android工程中接入Google Admob广告
我在上一篇文章 [Unity与Android]01-Unity与Android交互通信的简易实现) 中介绍了Unity与Android通讯的基本方法. 这一篇开始进入应用阶段,这次要介绍的是如何在An ...
- 在Android App中集成Google登录
技术文章 来源:码农网 发布:2016-09-19 浏览:194 摘要:今天,几乎所有的web和移动app都自带谷歌和Facebook登录,这对app开发者和用户来说是一个非常有用的功能,因为几乎每个 ...
- 在网页中添加google搜索
网页中插入谷歌搜索,至于怎么上谷歌,后面有时间会更,推荐百度 <form method="GET" action="http://www.google.com.hk ...
- 十大谷歌Google搜索技巧分享
前言:多数人在使用Google搜索的过程是非常低效和无谓的,如果你只是输入几个关键词,然后按搜索按钮,你将是那些无法得到Google全部信息的用户,在这篇文章中,Google搜索专家迈克尔.米勒将向您 ...
- 十大高明的Google搜索技巧
WHY 对于google检索,有时需要技巧会得到更好的检索结果,不用简单输入关键字检索后,一个个去浏览.对于这些技巧,基本都知道,但是如果不经常用,总是忘了,又得重新搜索下具体使用方法,这里就把它放到 ...
- Google官方关于Android架构中MVP模式的示例续-DataBinding
基于前面的TODO示例,使用Data Binding库来显示数据并绑定UI元素的响应动作. 这个示例并未严格遵循 Model-View-ViewModel 或 Model-View-Presenter ...
- android nfc中Ndef格式的读写
1. 在onCreate()中获取NfcAdapter对象: NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); 2.在onNewI ...
- 技术|程序员必须要学会Google搜索技巧
程序员必须要学会Google搜索技巧 摘要: 因为Google在我天朝被墙,学FQ请通过Bing进行搜索如何FQGoogle搜索技巧我曾经多次劝我的另一个朋友花10分钟学习一下Google通配符的使用 ...
- Android开发中遇到的requestFeature() must be called before adding content异常
缘起 上一篇博文中讲到了几种实现全屏显示Activity内容的方法.然而实际在实现中发现了一些问题,在本篇博文中进行总结下.首先交代一下开发环境,本人使用的是Android Studio 1.5.1, ...
随机推荐
- Matlab命令——目录操作(windows&Linux)
Matlab命令——目录操作(windows&Linux) 1. filesep用于返回当前平台的目录分隔符,Windows是反斜杠(\),Linux是斜杠(/).有时此命令结合ispc命令使 ...
- SublimeText3 初探(工欲善其事,必先利其器)
告别2015,迎来了2016.祝看到这篇博客的兄弟们都猴年发财,人生走上另一个高度. 新年新气象,猴年我会常常来更新自己的博客,希望能接触到更多的园友. sublime text3 和atom 各有各 ...
- Basic Sorting Algorithms
*稳定指原本数列中相同的元素的相对前后位置在排序后不会被打乱 快速排序(n*lgn 不稳定):数组中随机选取一个数x(这里选择最后一个),将数组按比x大的和x小的分成两部分,再对剩余两部分重复这个算法 ...
- [LeetCode] Missing Number (A New Questions Added Today)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 性能测试-Jmeter
缘由 很多情况下我们写程序过程中只会对固定模块采取并发限制,而且asp.net对于多线程也有他自己的处理机制,尤其对于注重业务,结果导向的团队可能更注重一定时间节点给出满意的产品,但是你的模块到底是否 ...
- poj 1004 Financial Management
求平均数,记得之前在杭电oj上做过一个求平均数的题目,结果因为题目是英文的,我就懵逼了 #include <stdio.h> int main() { ; double num; int ...
- Codeforces 583D. Once Again... (LIS变形)
题目链接:http://codeforces.com/contest/583/problem/D 给你t个长度为n的数组.问你最长不下降子序列的长度. 一开始用第一个n数组的lis和最后一个n数组的l ...
- c++/java/c# 几种编程语言的指针、引用比较
前一段时间,我在 cnblogs 别人的博客中,谈到: java 中的引用/指针,与 c++/C# 中的引用/指针不是一个概念. Java 引用,相当于 c++ 指针(fun3).Java 引用可以赋 ...
- hdu-4753-Fishhead’s Little Game-记忆化搜索
网赛的一道题目,当时没做出来. 由题意可知,最多只有12条边未知. 所以最多只有(1<<12)种状态. 所以记忆化搜索这种状态下,枚举添加任意一条边之后的状态的最优值. #include& ...
- maven 配置文件详解
<projectxmlns="http://maven.apache.org/POM/4.0.0 " xmlns:xsi="http://www.w3.org/20 ...