上篇文章講到《Android 簡訊的備份》,本文主要實現Android 簡訊的還原,即是將一條 佈局文件: 添加代碼: 添加許可權: 運行項目,搞定 ...
上篇文章講到《Android 簡訊的備份》,本文主要實現Android 簡訊的還原,即是將一條
佈局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:onClick="restoreSms" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="還原一條簡訊" /> </RelativeLayout>
添加代碼:
package com.wuyudong.smsrestore; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.view.Menu; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void restoreSms(View view) { Uri uri = Uri.parse("content://sms/"); ContentResolver resolver = getContentResolver(); ContentValues values = new ContentValues(); values.put("address", "110"); values.put("body", "你將被公安局監控,請速去報到"); values.put("date", System.currentTimeMillis()+""); values.put("type", "1"); //接受簡訊 resolver.insert(uri, values); Toast.makeText(this, "添加成功了", 0).show(); } }
添加許可權:
<uses-permission android:name="android.permission.READ_SMS"/> <uses-permission android:name="android.permission.WRITE_SMS"/>
運行項目,搞定