修改短信数据库,从而生成任意手机号发送的短信。

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 趣味应用—— 短信编辑器的更多相关文章

  1. android自动获取短信验证码

    前言:android应用的自动化测试必然会涉及到注册登录功能,而许多的注册登录或修改密码功能常常需要输入短信验证码,因此有必要能够自动获得下发的短信验证码.主要就是实时获取短信信息.android上获 ...

  2. android之发送短信程序

    首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...

  3. android自动填写短信验证码

    广播类 package com.examp.azuoyoutong.listner; import java.util.regex.Matcher;import java.util.regex.Pat ...

  4. Android通讯:短信

    Android通讯之短信功能实现: 使用android.telephony.SmsManager对象,可以发送短信和彩信.// 构造回调函数,短信发送结束后,会发出对应的Intent请求Intent ...

  5. Android自动读取短信验证码

    Android自动读取短信验证码  extends:http://www.cnblogs.com/jiayaguang/p/4366384.html,http://blog.csdn.net/yung ...

  6. Android开发之短信验证码示例

    在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...

  7. Android 学习第13课,android 实现发送短信的功能

    1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  8. 暴力清除Android中的短信

    有些短信程序有bug,当短信(特别是彩信)没有接收完整,或者是一些异常情况下,你会收到一条短信但是看不到或者看不了. 此时郁闷的事情就来了,系统会提醒你还有1条未读短信,但是你满世界都找不到这条短信. ...

  9. Android中读取短信信息

    Android中读取的短信文件有 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /**  * 所有的短信  */ public static final Strin ...

随机推荐

  1. 知乎布局||offsetTop||侧边栏自动等高

    1.对a标签的详细介绍 直接在a标签使用onclick,怎么去除a的默认链接,onclick="return test()" 注意这里的return 不可舍去,test函数可以直接 ...

  2. Django笔记-helloworld

    网上的Django资料太乱了,我想写一下自己的学习过程(只记大体过程,有时间就完善).(用eclipse+PyDev工具开发的) 1.项目结构 2.关键代码:(注意缩进,可能贴上来缩进格式等有变化,我 ...

  3. 从Microsoft.AspNet.Identity看微软推荐的一种MVC的分层架构

    Microsoft.AspNet.Identity简介 Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的mem ...

  4. [FMX] Android APP 启动黑屏优化补丁

    使用说明 *************************************************** Android APP 启动黑屏优化补丁 作者: Swish, YangYxd 201 ...

  5. xss利用和检测平台

    xssing 是安全研究者Yaseng发起的一个基于 php+mysql的 网站 xss 利用与检测开源项目,可以对你的产品进行黑盒xss安全测试,可以兼容获取各种浏览器客户端的网站url,cooki ...

  6. 跨区域的application共享问题。

    @1 new Thread(){ @Override public void run() { getConnect(); } }.start(); 如果我们的一个的应用程序有俩个入口.那么如果我们在这 ...

  7. 柱状堆积图Echarts

    Map<String,Object> map = new HashMap<String, Object>(); //图例的千人.双百 HashMap<String, St ...

  8. 四种生成和解析XML文档的方法详解(介绍+优缺点比较+示例)

    众所周知,现在解析XML的方法越来越多,但主流的方法也就四种,即:DOM.SAX.JDOM和DOM4J 下面首先给出这四种方法的jar包下载地址 DOM:在现在的Java JDK里都自带了,在xml- ...

  9. 新浪微博客户端(34)-block的细节与本质

    main.m #import <Foundation/Foundation.h> void test4(); int main(int argc, const char * argv[]) ...

  10. centos yum 安装

    LINUX下YUM源配置 1.确保RHEL5中已经安装了yum [root@lvs-master ~]# rpm -qa |grep yumyum-metadata-parser-1.1.2-3.el ...