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

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. jpa datasource config

    application.properties spring.datasource.driverClassName= spring.datasource.url= spring.datasource.u ...

  2. Win7 配置Apache+PHP+Mysql环境

    第一.安装并配置APACHE(安装到D:\phpapache\Apache2.2) 1.安装时默认安装,Network Domain, Server Name 我填写我的计算机名,Administra ...

  3. js blind使用

    $("#music_up").bind("click",showData()); $("#music_up").bind("cli ...

  4. 单点登录(SSO)系统的总结

    前些天一位其他开发部门的同事找到我们了解一些关于SSO单点登录的事,他们要做单点登录,同时也需要和我们这边的系统做集成,要我帮忙做一单点登录,了解关于单点登录的解决方案和资料,虽然做单点登录已经很久了 ...

  5. ReSharper 配置及用法(转)

    1:安装后,Resharper会用他自己的英文智能提示,替换掉 vs2010的智能提示,所以我们要换回到vs2010的智能提示 2:快捷键.是使用vs2010的快捷键还是使用 Resharper的快捷 ...

  6. SPL--Serializable

    Serializable[自定义序列化的接口] : 实现此接口的类将不再支持 __sleep() 和 __wakeup(). 作用: 为一些高级的序列化场景提供支持.__sleep()和__wakeu ...

  7. 求1到n的阶乘

    #include<stdio.h> int main() { int data; ; scanf("%d",&data); ){ int j; ;j<=d ...

  8. haproxy配置文件

    haproxy配置文件   思路:读一行.写一行 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 info de ...

  9. JQuery-EasyUI与EXTjs有什么区别?

    一.ExtJS1.ExtJS可以用来开发RIA也即富客户端的AJAX应用,是一个用javascript写的,主要用于创建前端用户界面,是一个与后台技术无关的前端ajax框架.因此,可以把ExtJS用在 ...

  10. angular-ngSanitize模块-$sanitize服务详解

    本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指令: ng-bing-html. 顾名思义,ng-bind-html和 ...