05 每10秒钟向手机里写短信

-------------------main.java--------------

package com.example.ju;


import android.content.ContentValues;

import android.net.Uri;

import android.os.Bundle;

import android.os.SystemClock;

import android.support.v7.app.ActionBarActivity;

import android.view.Menu;

import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 停30秒钟, 想系统短信数据库中写一条短信

new Thread(new Runnable() {

@Override

public void run() {

SystemClock.sleep(10 * 1000);

Uri uri = Uri.parse("content://sms/"); // 操作sms表的uri

ContentValues values = new ContentValues();

values.put("address", "95555");

values.put("type", "1");

values.put("body", "您的尾号为8890的账户, 收到100, 000, 000, 000.00元的转账. 活期余额为: 899, 777, 000, 111, 000.00元");

getContentResolver().insert(uri, values);

}

}).start();

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}


@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

}


、、、、、、、、、、、、权限、、、、

<uses-permission android:name="android.permission.WRITE_SMS"/>

    <uses-permission android:name="android.permission.READ_SMS"/>


你可能感兴趣的:(手机,定时写短信)