欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實現(xiàn)的短信編輯器功能示例

 更新時間:2017年08月10日 10:19:28   作者:woider  
這篇文章主要介紹了Android編程實現(xiàn)的短信編輯器功能,涉及Android權(quán)限控制、界面布局及短信功能相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android編程實現(xiàn)的短信編輯器功能。分享給大家供大家參考,具體如下:

修改短信數(shù)據(jù)庫,從而生成任意手機號發(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" />
  <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="短信發(fā)送者:"
      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="短信內(nèi)容" />
  </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="發(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;
  @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);
      }
    });
    //發(fā)送短信
    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, "短信內(nèi)容未填寫", Toast.LENGTH_SHORT).show();
          return;
        }
        //獲取電話號碼和短信內(nèi)容
        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();
      }
    });
  }
}

運行截圖:

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android短信與電話操作技巧匯總》、《Android文件操作技巧匯總》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

  • 基于Android6.0實現(xiàn)彈出Window提示框

    基于Android6.0實現(xiàn)彈出Window提示框

    這篇文章主要為大家詳細介紹了基于Android6.0實現(xiàn)彈出Window提示框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Android draw9patch 圖片制作與使用詳解

    Android draw9patch 圖片制作與使用詳解

    本文主要介紹Android draw9patch的圖片使用和制作,這里詳細說明如何操作,并幫大家整理了幾句口令,幫助大家記住,有興趣的小伙伴可以參考下
    2016-09-09
  • Android之FanLayout制作圓弧滑動效果

    Android之FanLayout制作圓弧滑動效果

    這篇文章主要介紹了Android之FanLayout制作圓弧滑動效果,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • Android?鼠標光標的圖形合成原理實例探究

    Android?鼠標光標的圖形合成原理實例探究

    這篇文章主要為大家介紹了Android?鼠標光標的圖形合成原理實例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2024-01-01
  • 解決Android模擬器端口被占用問題的辦法

    解決Android模擬器端口被占用問題的辦法

    這篇文章主要為大家分享了Android模擬器端口被占用問題的解決辦法,遇到Android模擬器端口被占用的時候,真的很頭疼,如何才能解決端口被占用的問題,下文為大家揭曉
    2015-12-12
  • Kotlin協(xié)程Context應用使用示例詳解

    Kotlin協(xié)程Context應用使用示例詳解

    這篇文章主要為大家介紹了Kotlin協(xié)程Context應用使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • Android利用HelloChart繪制曲線

    Android利用HelloChart繪制曲線

    這篇文章主要為大家詳細介紹了Android利用HelloChart繪制曲線,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Android判斷當前App是在前臺還是在后臺

    Android判斷當前App是在前臺還是在后臺

    這篇文章主要為大家詳細介紹了Android判斷當前App是在前臺還是在后臺的方法,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android自定義Dialog原理實例解析

    Android自定義Dialog原理實例解析

    這篇文章主要介紹了Android自定義Dialog原理實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • Android 雙擊返回鍵退出程序的方法總結(jié)

    Android 雙擊返回鍵退出程序的方法總結(jié)

    這篇文章主要介紹了Android 雙擊返回鍵退出程序的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下
    2017-06-06

最新評論