第一行代码系列第二章——更多隐式Intent用法(打开网页)
来源:互联网 发布:linux子目录权限设置 编辑:程序博客网 时间:2024/05/29 16:37
效果图
修改FirstActivity中按钮事件
Button button1 = (Button) findViewById(R.id.button_1);button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//Toast .makeText(FirstActivity .this, "you click the button 1", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://baidu.com")); startActivity(intent);}});
这样直接修改就可以
也可以自己建立一个活动,让他也能响应网页的Intent
新建third_layout.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button_3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 3" /> </LinearLayout>
新建活动ThirdActivity继承Activity
package com.example.activitytest;import android.app.Activity;import android.os.Bundle;import android.view.Window;public class ThirdActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.third_layout);}}
在菜单文件AndroidManifest.xml中注册一下
<activity android:name=".ThirdActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="http"/> </intent-filter> </activity>
运行效果图
除了http,还有geo表示显示地理位置,tel表示拨打电话
下面是调用系统拨号界面
Button button1 = (Button) findViewById(R.id.button_1);button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//Toast .makeText(FirstActivity .this, "you click the button 1", Toast.LENGTH_SHORT).show();// Intent intent = new Intent(Intent.ACTION_VIEW);// intent.setData(Uri.parse("http://baidu.com"));Intent intent = new Intent(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:10086")); startActivity(intent);}});}
效果图
0 0
- 第一行代码系列第二章——更多隐式Intent用法(打开网页)
- 第一行代码:更多隐式Intent的用法
- 第一行代码系列第二章——使用隐式Intent
- 第一行代码系列第二章——使用显式Intent在活动中穿梭
- Intent的用法——第一行代码阅读笔记
- 《第一行代码》第二章/Toast,Menu,Intent
- 入门Android开发--第一行代码--笔记系列(Intent)
- 第一行代码系列第二章——手动创建activity
- 第一行代码系列第二章——在activity中使用Toast
- 第一行代码系列第二章——向下一个活动传递数据
- 第一行代码总结:9.3服务的基本用法——服务的更多技巧(使用前台服务)
- Android--第一行代码 Intent用法
- 第一行代码阅读笔记----显示隐式Intent的基本用法
- 第一行代码Android 学习——第二章
- 【Android】《第一行代码—Android》第二章总结
- Android学习笔记—第一行代码第二章
- 第一行代码系列第二章——在活动中使用menu以及销毁一个活动
- 第一行代码系列第三章——自定义布局
- GCC___attribute__关键字和字节对齐
- 欢迎使用CSDN-markdown编辑器
- Linux 性能分析的前 60 秒
- 【翻译】Activity
- Cocos2dx3.0初认识
- 第一行代码系列第二章——更多隐式Intent用法(打开网页)
- Java基础__(环境变量配置,关键字,标识符,进制,数据类型,运算符)
- 数据类型---JavaScript
- html attributes properties
- 单例模式-基类单例。。用于其他单例的派生
- HDU1232-通畅工程
- POJ - 1016 - Prime Ring Problem(dfs)
- 苹果ios音频的回声消除处理
- [读书笔记]Android中Animation的Interpolator插值器详解(图文)