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

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. Github for Windows使用介绍

    Git已经变得非常流行,连Codeplex现在也已经主推Git.Github上更是充斥着各种高质量的开源项目,比如ruby on rails,cocos2d等等.对于习惯Windows图形界面的程序员 ...

  2. cmake 静态调用 c++ dll 的类的一个例子(Clion IDE)

    CMakeLists.txt project(aaa) add_library(aaa SHARED aaa.cpp) add_executable(bbb bbb.cpp) target_link_ ...

  3. FBX .NET

    https://github.com/returnString/ManagedFBX http://fbx.codeplex.com/ http://code.openhub.net/project? ...

  4. js正则,电话,邮箱

    1. <script type="text/javascript"> var str="Is this all th05777-89856825ere is5 ...

  5. js获取iframe里的body内容

    做个页面 需要加入a.html 使用的js动态添加iframe 直接JQ添加的 代码 $(".banner-box").after(“<iframe src="ht ...

  6. SpringMVC -rest风格修改删除

    REST风格

  7. 自定义列表dl的使用原因和场合

    为什么要使用自定义列表? dl和ol, ul的区别? 要正确理解dl的意图, 理解 dl的 "语义" ! 才能知道为什么要使用dl, 以及在什么时候/ 什么情况下使用 dl? dl ...

  8. linux网络:常用命令(一)

    1.ifconfig  可以查看Linux的网卡情况 ifconfig eth0 查看 eth0的信息 给一块网卡设置多个ip地址: ifconfig eth0:0 192.168.1.12 255. ...

  9. 在Linux下和Windows下遍历目录的方法及如何达成一致性操作

    最近因为测试目的需要遍历一个目录下面的所有文件进行操作,主要是读每个文件的内容,只要知道文件名就OK了.在Java中直接用File类就可以搞定,因为Java中使用了组合模式,使得客户端对单个文件和文件 ...

  10. 大熊君大话NodeJS之------Stream模块

    一,开篇分析 流是一个抽象接口,被 Node 中的很多对象所实现.比如对一个 HTTP 服务器的请求是一个流,stdout 也是一个流.流是可读,可写或兼具两者的. 最早接触Stream是从早期的un ...