Android 趣味应用—— 短信编辑器
生活随笔
收集整理的這篇文章主要介紹了
Android 趣味应用—— 短信编辑器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
修改短信數(shù)據(jù)庫,從而生成任意手機(jī)號(hào)發(fā)送的短信。
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" /><applicationandroid: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"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="短信發(fā)送者:"android:textSize="18sp" /><EditTextandroid:id="@+id/get_phone"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="7"android:inputType="phone" /></LinearLayout><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"><EditTextandroid:id="@+id/get_message"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="20dp"android:hint="短信內(nèi)容" /></ScrollView><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/get_time"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:text="添加當(dāng)前時(shí)間" /><Buttonandroid:id="@+id/send_message"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="4"android:text="發(fā)送短信" /></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;@Overrideprotected 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() {@Overridepublic 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() {@Overridepublic void onClick(View v) {if (TextUtils.isEmpty(getPhone.getText().toString())) {Toast.makeText(MainActivity.this, "電話號(hào)碼未填寫", Toast.LENGTH_SHORT).show();return;}if (TextUtils.isEmpty(getMessage.getText().toString())) {Toast.makeText(MainActivity.this, "短信內(nèi)容未填寫", Toast.LENGTH_SHORT).show();return;}//獲取電話號(hào)碼和短信內(nèi)容phoneNum = Integer.parseInt(getPhone.getText().toString());textSMS = getMessage.getText().toString();//開啟多線程Thread thread = new Thread() {@Overridepublic 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();}});} }
運(yùn)行截圖:
轉(zhuǎn)載于:https://www.cnblogs.com/woider/p/5140972.html
總結(jié)
以上是生活随笔為你收集整理的Android 趣味应用—— 短信编辑器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: USB_HID C#测试例程
- 下一篇: 封装了一套WeCenter的IOS SD