Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the function of short message Editor in Android

Shulou Source: shulou.com Published: 2022-05-31 22:03:21 09月21日 Update

This article mainly explains "how to achieve the short message editor function in Android". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve the short message editor function in Android".

AndroidManifest.xml

Activity_main.xml

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); / / registered control 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); / / get the current time getTime.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {textSMS = getMessage.getText () .toString (); SimpleDateFormat formatter = new SimpleDateFormat ("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Date curDate = new Date (System.currentTimeMillis ()); / / get the current time currentTime = formatter.format (curDate); textSMS = textSMS + currentTime; getMessage.setText (textSMS);}}) / / send SMS sendMessage.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (TextUtils.isEmpty (getPhone.getText (). ToString () {Toast.makeText (MainActivity.this, "phone number not filled in", Toast.LENGTH_SHORT) .show (); return } if (TextUtils.isEmpty (getMessage.getText (). ToString ()) {Toast.makeText (MainActivity.this, "SMS content is not filled in", Toast.LENGTH_SHORT) .show (); return;} / / get the phone number and text message content phoneNum = Integer.parseInt (getPhone.getText (). ToString ()); textSMS = getMessage.getText (). ToString () / / enable multithreading 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, "SMS generated successfully", Toast.LENGTH_SHORT). Show ();}}) }} Thank you for your reading. The above is the content of "how to achieve the SMS editor function in Android". After the study of this article, I believe you have a deeper understanding of how to achieve the SMS editor function in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: SMS function editor content study number time phone phone number success that is ideas situations controls articles more knowledge knowledge points articles threads Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Shulou Information Linux Redmi