Android中怎么實現(xiàn)短信編輯器功能-創(chuàng)新互聯(lián)

Android中怎么實現(xiàn)短信編輯器功能,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

我們注重客戶提出的每個要求,我們充分考慮每一個細節(jié),我們積極的做好成都網站設計、網站制作服務,我們努力開拓更好的視野,通過不懈的努力,創(chuàng)新互聯(lián)贏得了業(yè)內的良好聲譽,這一切,也不斷的激勵著我們更好的服務客戶。 主要業(yè)務:網站建設,網站制作,網站設計,小程序開發(fā),網站開發(fā),技術開發(fā)實力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據庫的技術開發(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="短信內容" />
  </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, "短信內容未填寫", 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中怎么實現(xiàn)短信編輯器功能的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

分享題目:Android中怎么實現(xiàn)短信編輯器功能-創(chuàng)新互聯(lián)
文章源于:http://muchs.cn/article28/dpsojp.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供品牌網站制作、App開發(fā)、網站策劃移動網站建設、面包屑導航、靜態(tài)網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網站建設