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.这个是万金油.可以有调用各种功 ...
随机推荐
- 结构体buf_chunk_t
/** Buffer pool chunk comprising buf_block_t */ typedef struct buf_chunk_struct buf_chunk_t; /** A c ...
- UEFI GPT
其实关于UEFI的几篇文章很早就写下了,只是自己读了一遍感觉很不满意,就决定重写.目的是想用最简单直白的语言把内容写出来,让每个人都能轻松读懂.当然,如果你已经对这些内容有了很深的理解的话,这篇文章除 ...
- 利用icepdf将pdf文件转为图片
所需jar 包为icepdf-core.jar.icepdf-extra.jar.icepdf-pro-intl.jar.icepdf-pro.jar和icepdf-viewer.jar. 示例代码如 ...
- 【JS】打印Excel——ActiveX控件
function viewToExcel(){ var filepath = "f:\\PrinterExcel.xls"; var xlApp; var xlBook; var ...
- Android样式——Styles
说明 样式(style)是属性的集合,用来指定View或者Window的外观和格式. 这些属性可以是height(高度).padding(内边距).font size(字体颜色)等. 样式定义在另一个 ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
- the type initializer for '' threw an exception
the type initializer for '' threw an exception 问题:程序启动时初始化主窗口类时,弹出该错误.调查:查看类的构造函数是否会有异常抛出.解决:去掉类的构造函 ...
- MFC无边框窗体不响应任务栏点击问题
为了提升用户体验,需要隐藏主窗体的边框,使用图片绘制新的标题栏.标题栏绘制之后,发现用户点击任务栏上应用程序的图标,应用程序不会随着点击交替隐藏显示. 分析结果是问题出现窗体风格设置上. 最初为了省事 ...
- HDU4289 Control 最大流
经典题,求去掉若干个点,使得两个点不在连通,总价值最少 所以拆点最小割,除了拆点边,流量都为无穷,拆点边是流量为价值 #include <iostream> #include <cs ...
- HDU5593 ZYB's Tree 树形DP +分治
感觉其实就是树分治,一次BC的题,感觉这次题目质量比较高,仅代表蒟蒻的看法 一次DFS获取每个点到子树的距离不大于K的点的个数, 然后一遍BFS获取从每个点父亲不大于K的的个数,层层扩展,还是想说 其 ...