国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現的短信編輯器功能示例

2019-10-22 18:30:11
字體:
來源:轉載
供稿:網友

本文實例講述了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,短信,編輯器

Android,短信,編輯器

 

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高台县| 兴安盟| 日照市| 嵩明县| 武功县| 宣化县| 白沙| 出国| 鲁山县| 土默特右旗| 霸州市| 佛冈县| 吉首市| 淅川县| 京山县| 靖边县| 南溪县| 景谷| 大足县| 汽车| 兴义市| 全椒县| 和田县| 宁强县| 聂拉木县| 浙江省| 个旧市| 榆树市| 军事| 榆社县| 冕宁县| 镇远县| 湾仔区| 台中县| 克东县| 台湾省| 虎林市| 民乐县| 无锡市| 万源市| 萨嘎县|