一、拨打电话

1、首先做好界面,代码如下:

layout =>activity_main.xml 中

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/head_lable" /> <EditText
android:id="@+id/txt_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_dialer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
android:layout_gravity="right"
/> </LinearLayout>

效果图如下 :

2、下面就点击拨号事件进行操作:

1)点击拨号按钮=》获取拨号的id==>监听拨号事件setOnClickListener的一个新方法。

2)实现这个方法

2.1)获取编辑框的id==>然后获取其值。

2.2)获取值以后就是要实现打电话的意图啊new一个意图。

意图的动作是打电话、获取电话号码。

2.3)把这个意图告诉系统(startActivity(intent);)

3)加入打电话的权限(在AndroidManifest.xml中)。<uses-permission android:name="android.permission.CALL_PHONE"/>

src=>cn.rfvip.dialer0204=>MainActivity.java 中

package cn.rfvip.dialer0204;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//给按钮一个监听事件
Button bt=(Button) findViewById(R.id.btn_dialer);
bt.setOnClickListener(new MyLisen()); //1、首先获取按钮的id==>然后监听 事件==》获取文本的id==>然后获取其值==》意图是打电话(new一个)==》打电话动作、电话号码(加Tel)。
//把意图告诉系统;
//打电话的权限加入 } class MyLisen implements OnClickListener{ @Override
public void onClick(View v) {
// TODO 自动生成的方法存根 EditText eT=(EditText) findViewById(R.id.txt_number);
String phone=eT.getText().toString(); Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phone));
startActivity(intent);
}} }

二、发送短信

在activity_main.xml

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:id="@+id/ed_sms_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="短信号码"
/>
<EditText
android:id="@+id/ed_sms_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="短信内容"
android:gravity="top"
android:lines="5"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="sengsms"
android:onClick="sendsms"
/> </LinearLayout>

在MainActivity.java

package cn.rfvip.sendsms;

import android.os.Bundle;
import android.app.Activity;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.EditText; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendsms(View v) {
EditText ed_sms_phone=(EditText) findViewById(R.id.ed_sms_phone);
EditText ed_sms_content=(EditText) findViewById(R.id.ed_sms_content);
String sms_phone = ed_sms_phone.getText().toString();
String sms_content = ed_sms_content.getText().toString(); SmsManager sm=SmsManager.getDefault();//获取短信管理器

ArrayList<String> smss= sm.divideMessage(sms_content);//分割短信
    for(String string:smss)
   {
   sm.sendTextMessage(sms_phone, null, string, null, null);

}


}

}

记得加入发送短信权限哦    <uses-permission android:name="android.permission.SEND_SMS"/>

android 入门 002 (拨打电话,发送短信)的更多相关文章

  1. Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘

    apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...

  2. iOS_拨打电话/发送短信

    GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git 功能一: 拨打电话 1.可以有提示框.提示该电话号 ...

  3. 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信

    1.Flutter url_launcher 模块    Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能.    https://p ...

  4. Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

    家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...

  5. IOS中调用系统拨打电话发送短信

    一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...

  6. android使用Intent操作拨打号码发送短信

    Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...

  7. html5 安卓拨打电话 发短信

    方法一: <input name=”phone_no” format=”*m” value=”13″/> <do type=”option” label=”呼出号”> < ...

  8. android中调用系统的发送短信、发送邮件、打电话功能

    1 调用发送短信功能: Uri smsToUri = Uri.parse("smsto:");  Intent sendIntent = new Intent(Intent.ACT ...

  9. Android面试收集录 电话、短信和联系人、多媒体技术

    1.请写出调用系统拨号界面? Intent intent=new Intent(Intent.ACTION_DIAL,Uri.pase("tel:12345678910")); s ...

随机推荐

  1. fackbook的Fresco (FaceBook推出的Android图片加载库-Fresco)

    [Android开发经验]FaceBook推出的Android图片加载库-Fresco   欢迎关注ndroid-tech-frontier开源项目,定期翻译国外Android优质的技术.开源库.软件 ...

  2. shell 命令

  3. linux-统计一个文件中出现的单词数

    #!/bin/bash ] then echo "Usage: $0 filename"; exit - fi filename=$ egrep -o "\b[[:alp ...

  4. RMAN备份演练进阶篇

    前篇介绍了通过rman进行各种备份,进阶篇则主要是rman的一些功能扩展和增加功能,利用前篇你已经完全可以完成数据库的备份,而通过本篇你可以更好更方便的完成数据库的备份. 一.建立增量备份 如果数据库 ...

  5. js对象遍历

    js对象遍历可以使用比较普遍的方法:如下 var ss={aa:"aa",bb:"bb"}; for(var s in ss){ console.info(&q ...

  6. 关闭微软对win10的推送

    找到windows中安装的更新,卸载 KB3035583 这个更新即可

  7. OpenStack 之vmware机器迁移到openstack集群

    原理 openstack本身是支持使用vmware格式的镜像的,但是是需要我们我们在/etc/nova/nova.conf的配置文件中指定该计算节点使用vmware的驱动 1 2 3 4 5 6 7 ...

  8. expandlistview

    package com.exaple.zhonghe2; import java.sql.SQLData;import java.util.ArrayList;import java.util.Has ...

  9. Android之自定义生成彩色二维码

    先导个zxing.jar包 下面是xml布局 activity_main.xml <RelativeLayout xmlns:android="http://schemas.andro ...

  10. Android开机自启动程序

    背景知识:当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为 android.intent.action.BOOT_COMPLETED. ...