Android中怎么實(shí)現(xiàn)短信編輯器功能,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先制作網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有銅陵免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
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); //注冊(cè)控件 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); //獲取當(dāng)前時(shí)間 getTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { textSMS = getMessage.getText().toString(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH時(shí)mm分ss秒"); Date curDate = new Date(System.currentTimeMillis());//獲取當(dāng)前時(shí)間 currentTime = formatter.format(curDate); textSMS = textSMS + currentTime; getMessage.setText(textSMS); } }); //發(fā)送短信 sendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (TextUtils.isEmpty(getPhone.getText().toString())) { Toast.makeText(MainActivity.this, "電話號(hào)碼未填寫(xiě)", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(getMessage.getText().toString())) { Toast.makeText(MainActivity.this, "短信內(nèi)容未填寫(xiě)", Toast.LENGTH_SHORT).show(); return; } //獲取電話號(hào)碼和短信內(nèi)容 phoneNum = Integer.parseInt(getPhone.getText().toString()); textSMS = getMessage.getText().toString(); //開(kāi)啟多線程 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(); } }); } }
看完上述內(nèi)容,你們掌握Android中怎么實(shí)現(xiàn)短信編輯器功能的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!