之前我们粗略讲了Intent作用,准确的说两个Activity之间只有通过android.content.Intent这个类才能传递消息,传递的消息有哪几种呢,intent主要分为7种:
- 操作(Action)
- 数据(Data)
- 数据类型(Type)
- 操作类别(Category)
- 附加信息(Extras)
- 组件(Component)
- 标签(Flags)
操作类型:
1.ACTION_MAIN 程序入口不需要接受程序
2.ACTION_VIEW 数据显示
以及调用拨号程序、编辑给定数据、对于一组数据的选择、运行数据、调用发送短信程序、根据制定TYPE打开操作内容的Intent、创建文件操作选择器
数据:
描述ntent所描述数据的URI及类型,可以通过setData来设置。
1.浏览网页 http://网页地址
2.拨打号码 tel:电话号码
3.发送短信 smsto:短信接收人号码
4.查找sd卡文件 file:///sdcard
5.显示地图 geo:坐标,坐标
设置数据要用到net.Uri类
type:
短信,文本,图片,音乐
附件信息
短信,彩信,email操作
接下来我们来做一个小浏览器,打开一个网页
主布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:ems="10" /> <ImageButton android:id="@+id/search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/editText1" android:layout_alignParentRight="true" android:layout_alignTop="@+id/editText1" android:layout_marginRight="14dp" android:layout_toRightOf="@+id/editText1" android:background="@drawable/check" android:onClick="start" android:src="@android:drawable/btn_star" /> </RelativeLayout>
可见我们这里将按钮绑定监听方法,这样我们在Activity里面只需要监听即可
Activity代码
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void start(View view){ Uri uri=Uri.parse("https://www.baidu.com/");//要进入的网址 Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW);//设置Action intent.setData(uri);//设置数据 MainActivity.this.startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
很简单的给出地址,直接跳转到当前手机的浏览器并传递要浏览的地址
效果如图:
这里也可以手动输入搜索地址
小编这里就不写了,能简单轻松实现
相关推荐
1、IntentCaseProject(打开网页).rar 2、IntentCaseProject(拨打电话) 3、IntentCaseProject(直接呼出) 4、IntentCaseProject(发送短信) 5、IntentCaseProject(发送彩信) 6、IntentCaseProject(发送邮件...
实验三 Android网络通信 实验目的: 本实验的目的是使学生深入了解利用Intent实现进程间的通信过程。学会利用Inten t进行Activity的跳转,以及链接网页信息;学会利用Intent将其他Activity的信息返回 到Activity中的...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.2 在程序里浏览网页——WebView.loadUrl 8.3 嵌入HTML标记的程序——WebView.loadData 8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter ...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...
8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...