Intent意图打开电话、邮件、短信、地图、上网
来源:互联网 发布:鹏博士云计算业务中心 编辑:程序博客网 时间:2024/05/29 14:31
####1、界面显示
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.lumeng.myapplication.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_call" android:text="@string/call" android:layout_marginTop="30dp" android:textSize="30dp"/> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_email" android:text="@string/email" android:textSize="30dp"/> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_mes" android:text="@string/mes" android:textSize="30dp"/> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_map" android:text="@string/map" android:textSize="30dp"/> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_wep" android:text="@string/wep" android:textSize="30dp"/> <Button android:layout_width="match_parent" android:layout_height="80dp" android:id="@+id/bt_search" android:text="@string/search" android:textSize="30dp"/> </LinearLayout></RelativeLayout>
2、功能实现
package com.example.lumeng.myapplication;import android.app.SearchManager;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button call,msg,email,map,wep; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); call = (Button) findViewById(R.id.bt_call); msg = (Button) findViewById(R.id.bt_mes); email = (Button) findViewById(R.id.bt_email); map = (Button) findViewById(R.id.bt_map); wep = (Button) findViewById(R.id.bt_wep); call.setOnClickListener(this); msg.setOnClickListener(this); email.setOnClickListener(this); map.setOnClickListener(this); wep.setOnClickListener(this); } @Override public void onClick(View view) { int id =view.getId(); Intent it = new Intent(); switch (id) { case R.id.bt_call: it.setAction(Intent.ACTION_VIEW);//设置动作,显示数据,显示拨号界面 //it.setAction(Intent.ACTION_CALL);//直接拨打 it.setData(Uri.parse("tel:10086"));//设置uri指定电话号码 break; case R.id.bt_email: it.setData(Uri.parse("mailto:service@flag.com.tw")); //收件人 it.putExtra(Intent.EXTRA_CC,new String[] {"test@flag.com.tw"});//抄送人 it.putExtra(Intent.EXTRA_SUBJECT,"数据已经收到");//设置主题 it.putExtra(Intent.EXTRA_TEXT,"谢谢");//设置内容 break; case R.id.bt_mes: it.setData(Uri.parse("sms:10086?body=话费"));//短信号码和内容 break; case R.id.bt_wep: it.setData(Uri.parse("http://www.baidu.com/?from=wap")); //链接网址 break; case R.id.bt_map: it.setData(Uri.parse("geo:39.896086,116.151147"));//地图坐标 break; case R.id.bt_search: it.setAction(Intent.ACTION_SEARCH);//将动作改为搜索 it.putExtra(SearchManager.QUERY,"长城"); break; default: break; } startActivity(it);//寻找适合意图的程序,多个会出现选择。 }}
文献参考:
android app开发入门 施威铭 编著
本人郑重声明,本博客所著文章、图片版权归权利人持有,本博只做学习交流分享所用,不做任何商业用途。访问者可將本博提供的內容或服务用于个人学习、研究或欣赏,不得用于商业使用。同時,访问者应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人的合法权利;如果用于商业用途,须征得相关权利人的书面授权。若以上文章、图片的原作者不愿意在此展示內容,请及时通知在下,將及时予以刪除。
阅读全文
0 0
- Intent意图打开电话、邮件、短信、地图、上网
- 调用iPhone的地图、电话、邮件、短信及内容
- iPhone开发之调用系统地图、邮件、电话、短信、浏览器
- iOS 之调用地图、电话、邮件和短信
- intent 打电话 发短信 发邮件 google地图 相关用法
- 电话短信和邮件
- iOS 打开系统打电话 发短信 邮件 浏览器 地图
- 短信,电话,邮件,提示框
- 短信,电话,邮件,提示框
- iOS 邮件 电话 短信 safari
- iOS 电话 短信 邮件等等
- iOS 电话 短信 邮件 详解
- iOS调用电话、短信、邮件
- 邮件、短信分享 推荐、电话
- Android开发:使用Intent打开电话、短信、邮箱、本地文件等系统应用程序整理大全
- iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- iOS开发笔记--调用iPhone的短信、地图、电话、邮件、浏览器
- iOS 程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- darwin之socket与Task关联
- lua 获取某个数精确到小数点后n位的结果
- Json的增删查改
- 浮点数计算后,强制转换成整型的问题
- hashMap和hashTable
- Intent意图打开电话、邮件、短信、地图、上网
- 文件字节输出流--FileOutputStream
- (0070)iOS开发之AVFoundation枚举属性注解
- SQL Server(MSSQLSERVER) 请求失败或服务未及时响应,有关详细信息,请参见事件日志或其他的适用的错误日志。
- 实操《深入浅出React和Redux》第三期—Redux
- Docker Compose进行多容器创建与日常维护
- 互联网架构,如何进行容量设计?
- C语音基础类型
- ES6学习之路5----数组方法