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 ...
随机推荐
- 自然语言13_Stop words with NLTK
https://www.pythonprogramming.net/stop-words-nltk-tutorial/?completed=/tokenizing-words-sentences-nl ...
- vs2013安装闪退及vs2010 vs2013打开时提示 未能完成的操作 及vs2013安装时出现图片后闪退
vs2013打开时提示如上图,vs2010只有 未能完成的操作 这样的提示. 这时.net 4.0开发的程序打开也毫无反应,应该是.net framework出了问题.查看控制面板-卸载程序,发现 ...
- iOS / Android 移动设备中的 Touch Icons
上次转载了一篇<将你的网站打造成一个iOS Web App>,但偶然发现这篇文章的内容有些是错误的——准确来说也不是错误,只是不适合自半年前来的情况了(也可以说是iOS7 之后的时间)—— ...
- marshal intptr to delegate
http://www.codeproject.com/Tips/441743/A-look-at-marshalling-delegates-in-NET https://msdn.microsoft ...
- DllMaps
http://www.mono-project.com/docs/advanced/pinvoke/dllmap/ http://www.mono-project.com/docs/advanced/ ...
- UIAlertController 标题文字大小 颜色
NSString *title = [NSString stringWithFormat:]; NSString *msg = @"\n把红包分享给微信好友,金额随机,可用于购买雪票和雪卡& ...
- 事务环境下的CombGuid
一直使用osharp,osharp3使用的是combguid,代码如下 /// <summary> /// 返回Guid用于数据库操作,特定的时间代码可以提高检索效率 /// </s ...
- Orchard源码分析(5.2):BeginRequest事件处理(DefaultOrchardHost.BeginRequest方法)
BeginRequest事件处理的作用是确保所有Shell已经加载,或者在扩展有变化的时候重新加载. void IOrchardHost .BeginRequest() { ...
- Java并发编程核心方法与框架-exchanger的使用
Exchanger可以使两个线程之间传输数据,比生产者/消费者模式使用wait/notify更加方便. Exchanger中的exchange()方法具有阻塞的特点,此方法被调用后等待其他线程来取数据 ...
- Mount挂载命令使用方法
语法: mount -t 类型 -o 挂接方式 源路径 目标路径 -t 详细选项: 光盘或光盘镜像:iso9660 DOS fat16文件系统:msdos Windows 9x fat32文件 ...