android开发学习:打电话和发短信
1.新建一个android项目
File——New——Other——android application project
填写application name(就是应用的名字。比方:天天酷跑)
填写project name(就是程序项目名。比方:TTKP。打包后名字也是TTKP.APP)
填写package name(程序包名。比方cn.tengxun.ttkp)
然后选择最小执行的android版本号,最适合版本号。编译版本号。主题。
NEXT——NEXT——选择你android应用图标图片,然后完毕。
然后我们要关注的res(放资源文件的,静态的文字能够写在里面)
src代码编程文件
gen(自己主动生成的资源ID生成文件)
AndroidManifest.xml是应用配置文件
res下的layout是布局的配置文件
2.编写一个打电话功能
先编写布局配置文件activity_main.xml
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone_title" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_title"
android:id="@+id/telnum" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phone_button"
android:id="@+id/button"/> </LinearLayout>
@的意思是操作gen以下的R.java文件的信息。获取;@+是创建。
编写一下文本的信息
res以下的value下的string.xml
<? xml version="1.0" encoding="utf-8"? >
<resources> <string name="app_name">拨号器</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="phone_title">请输入手机号</string>
<string name="phone_button">拨号</string> </resources>
编写拨号事件代码
在src下的java代码
public class MainActivity extends Activity {
private EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext=(EditText) findViewById(R.id.telnum);
Button button=(Button) this.findViewById(R.id.button);
button.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String telnum=edittext.getText().toString();
Intent intent=new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:"+telnum));
startActivity(intent);
}
}}
最后你要获取你调用android打电话这个功能的权限
在AndroidManifest.xml应用配置文件
<uses-permission android:name="android.permission.CALL_PHONE" />
3.编写发短信功能
布局配置文件
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_title"
android:id="@+id/telnum" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="3"
android:hint="@null"
android:id="@+id/message"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/message_button"
android:id="@+id/message_button"/>
string配置文件
<string name="message_button">发送短信</string>
java代码
public class MainActivity extends Activity {
private EditText phonetext;
private EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phonetext=(EditText) findViewById(R.id.telnum);
edittext=(EditText) findViewById(R.id.message);
Button message_button=(Button) this.findViewById(R.id.message_button);
message_button.setOnClickListener(new MessageButtonClickListener());
}
private final class MessageButtonClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String phoneNumber=phonetext.getText().toString();
String message=edittext.getText().toString();
SmsManager manager=SmsManager.getDefault();
ArrayList<String> messages = manager.divideMessage(message);
for(String content:messages){
//发短信
manager.sendTextMessage(phoneNumber, null, content, null, null);
//写入短信记录
ContentValues values = new ContentValues();
values.put("address", phoneNumber);
values.put("body", message);
values.put("type", "2");
values.put("read", "1");//1表示已读
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
}
Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show();
}
}
}
增加权限
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
android开发学习:打电话和发短信的更多相关文章
- IOS 开发调用打电话,发短信
1.调用 自带mail[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzl ...
- IOS 开发,调用打电话,发短信,打开网址
IOS 开发,调用打电话,发短信,打开网址 1.调用 自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString: ...
- android打电话、发短信实现
打电话: Intent intent = newIntent(Intent.ACTION_CALL,Uri.parse("tel:"+"156666666666" ...
- Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)
结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...
- iOS学习笔记(十四)——打电话、发短信
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- 打电话、发短信、web以及发邮件
#import "ViewController.h" #import <MessageUI/MessageUI.h> //导入信息UI库 @interface View ...
- 代码控制打电话、发短信、发邮件、打开手机app等操作
很多时候我们需要利用我门自己的app进行一些打电话.发短信等的操作,那么如何利用代码实现呢,下面就介绍一些简单的方法来实现这些操作. 一.打电话: <1>最简单.最直接的方法----直接跳 ...
- iOS10打电话、发短信、发邮件等小功能
注意:iOS10.0以后,使用openURL会有延迟,需要使用 openURL: options: completionHandler: 一.概要 本文中主要就是介绍在iOS中实现打电话.发短信.发邮 ...
- delphi xe5 android 开发实现手机打电话和发短信
转载自 http://www.raysoftware.cn/ 其实都可以通过intent和URI调用系统功能.Windows程序员可以理解成是ShellExecute.这个是万金油.可以有调用各种功 ...
随机推荐
- poj 2109 Power of Cryptography (double 精度)
题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...
- mvc 相关js
http://modernizr.com/ https://github.com/Modernizr/Modernizr/wiki 主要看下Polyfills 用于html5,用于一些老ie,fire ...
- bzoj1001
平面图求最小割: 其实看bzoj1001一开始着实把我怔住了 AC的人暴多,可自己完全没思路 后来看了某大牛的ppt,才会做 一个月前做这题的吧,今天来简单回忆一下: 首先是欧拉公式 如果一个连通的平 ...
- Ajax时代 SQL注入依然是隐患
许多网站程序在编写时,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患.用户可以提交一段数据库查询代码(一般是在浏览器地址栏进行,通过正常的www端口访问),根据程序返回的结果,获得某些想得 ...
- Android Service即四大组件总结
原文转载自:http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html Service 服务: 一个Service 是一段长 ...
- 如何使用spring中的Log4jConfigListener--删除
使用spring中的Log4jConfigListener有如如下好处: 1. 动态的改变记录级别和策略,不需要重启Web应用,如<Effective Enterprise Java> ...
- 制作动态链接库给opencv程序使用(使用QtCreator)
新建一个c++库项目 pro文件 #------------------------------------------------- # # Project created by QtCreator ...
- 设计模式_Bridge
形象的例子: —早上碰到MM,要说早上好,晚上碰到MM,要说晚上好:碰到MM穿了件新衣服,要说你的衣服好漂亮哦,碰到MM新做的发型,要说你的头发好漂亮哦.不要问我“早上碰到MM新做了个发型怎么说”这种 ...
- IoSkipCurrentIrpStackLocation .(转)
原文链接:http://m.blog.csdn.net/blog/ruanben/19758769# 当驱动被分层以后,他们被注册到一个chain中,IRP会在这个chain中传递,从最上面,到最下面 ...
- python网络编程(六)---web客户端访问
1.获取web页面 urllib2 支持任何协议的工作---不仅仅是http,还包括FTP,Gopher. import urllib2 req=urllib2.Request('http://www ...