Android 趣味应用—— 短信编辑器
修改短信数据库,从而生成任意手机号发送的短信。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dudon.fakesms"> <uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" /> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
activity_main.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"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="短信发送者:"
android:textSize="18sp" /> <EditText
android:id="@+id/get_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="7"
android:inputType="phone" /> </LinearLayout> <ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"> <EditText
android:id="@+id/get_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:hint="短信内容" /> </ScrollView> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button
android:id="@+id/get_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="添加当前时间" /> <Button
android:id="@+id/send_message"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="发送短信" /> </LinearLayout> </LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private int phoneNum;
private String textSMS;
private String currentTime;
private Button sendMessage;
private Button getTime;
private EditText getPhone;
private EditText getMessage; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//注册控件
sendMessage = (Button) findViewById(R.id.send_message);
getTime = (Button) findViewById(R.id.get_time);
getPhone = (EditText) findViewById(R.id.get_phone);
getMessage = (EditText) findViewById(R.id.get_message); //获取当前时间
getTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textSMS = getMessage.getText().toString();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
currentTime = formatter.format(curDate);
textSMS = textSMS + currentTime;
getMessage.setText(textSMS);
}
});
//发送短信
sendMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(getPhone.getText().toString())) {
Toast.makeText(MainActivity.this, "电话号码未填写", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(getMessage.getText().toString())) {
Toast.makeText(MainActivity.this, "短信内容未填写", Toast.LENGTH_SHORT).show();
return;
}
//获取电话号码和短信内容
phoneNum = Integer.parseInt(getPhone.getText().toString());
textSMS = getMessage.getText().toString(); //开启多线程
Thread thread = new Thread() {
@Override
public void run() { ContentResolver resolver = getContentResolver();
ContentValues values = new ContentValues();
values.put("address", phoneNum);
values.put("type", 1);
values.put("date", System.currentTimeMillis());
values.put("body", textSMS);
resolver.insert(Uri.parse("content://sms"), values);
}
};
thread.start();
Toast.makeText(MainActivity.this, "短信成功生成", Toast.LENGTH_SHORT).show();
}
});
}
}
运行截图:
Android 趣味应用—— 短信编辑器的更多相关文章
- android自动获取短信验证码
前言:android应用的自动化测试必然会涉及到注册登录功能,而许多的注册登录或修改密码功能常常需要输入短信验证码,因此有必要能够自动获得下发的短信验证码.主要就是实时获取短信信息.android上获 ...
- android之发送短信程序
首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...
- android自动填写短信验证码
广播类 package com.examp.azuoyoutong.listner; import java.util.regex.Matcher;import java.util.regex.Pat ...
- Android通讯:短信
Android通讯之短信功能实现: 使用android.telephony.SmsManager对象,可以发送短信和彩信.// 构造回调函数,短信发送结束后,会发出对应的Intent请求Intent ...
- Android自动读取短信验证码
Android自动读取短信验证码 extends:http://www.cnblogs.com/jiayaguang/p/4366384.html,http://blog.csdn.net/yung ...
- Android开发之短信验证码示例
在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...
- Android 学习第13课,android 实现发送短信的功能
1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- 暴力清除Android中的短信
有些短信程序有bug,当短信(特别是彩信)没有接收完整,或者是一些异常情况下,你会收到一条短信但是看不到或者看不了. 此时郁闷的事情就来了,系统会提醒你还有1条未读短信,但是你满世界都找不到这条短信. ...
- Android中读取短信信息
Android中读取的短信文件有 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /** * 所有的短信 */ public static final Strin ...
随机推荐
- HTML学习笔记——块级标签、行级标签、图片标签
1>块级标签.行级标签 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...
- (转)HBase 的原理和设计
转自:HBase的原理和设计 HBase架构:
- 关于软件工程结对编程作业 PairProject : Elevator Scheduler(电梯调度算法的实现与测试)的总结
1)结对编程队友 1106xxxx 张扬 1106xxxx 杨军 其中,此项目的编程实现主要由前者完成. 2)关于结对编程 结对编程的优点: 最直接的一点:在结对编程中,由于有另一个人在你身边和你配合 ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- C#--使用存储过程
过程: 1.连接数据库 2.设置执行类型为存储过程,区别于SQL语句 3.得到执行结果,返回值.输出参数等 //连接数据库 string connstr = "Data Source=ZGC ...
- Photoshop 融合属性 Unity Shader
http://forum.unity3d.com/threads/free-photoshop-blends.121661/
- 修改输入框placeholder文字默认颜色-webkit-input-placeholder
html5为input添加了原生的占位符属性placeholder,高级浏览器都支持这个属性,例如: <input type="text" placeholder=" ...
- ecshop去头部和掉底部版权
1.去掉头部版权 打开includes/lib_main.php $page_title = $GLOBALS['_CFG']['shop_title'] . ' - ' . 'Powered by ...
- 全选,全不选,反选的js实现
全选练习 ** 使用复选框上面一个属性判断是否选中 - checked属性 - checked=true:选中 ...
- Python开发【第七篇】:面向对象
Python之路[第五篇]:面向对象及相关 面向对象基础 基础内容介绍详见一下两篇博文: 面向对象初级篇 面向对象进阶篇 其他相关 一.isinstance(obj, cls) 检查是否obj是否 ...