iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android中怎么实现短信编辑器功能
  • 378
分享到

Android中怎么实现短信编辑器功能

android 2023-05-30 21:05:55 378人浏览 独家记忆
摘要

Android中怎么实现短信编辑器功能,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。AndroidManifest.xml<?xml version="

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中怎么实现短信编辑器功能的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网精选频道,感谢各位的阅读!

--结束END--

本文标题: Android中怎么实现短信编辑器功能

本文链接: https://www.lsjlt.com/news/221667.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作