Content://sms

 

package com.example.sms;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Telephony.Sms.Conversations;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener {

    private Button bt = null;
    private EditText et_number = null;
    private EditText et_body = null;
    private EditText et_time = null;
    
        //号码和短信内容提取
    private String str_number = null;
    private String str_body = null;
    
    //休眠时间设置
    private long time = 0;
    
    private Notification note = null;
     
        //初始化
    private void init(){
        bt = (Button)findViewById(R.id.bt);
        et_number = (EditText)findViewById(R.id.et_number);
        et_body = (EditText)findViewById(R.id.et_body);
        et_time = (EditText)findViewById(R.id.et_time);
    }
    
        //主进程
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //my code below
        
        //初始化
        init();
        
        //按钮点击事件
        bt.setOnClickListener(this);
        
        
                
    }


       //状态栏设置    
    private void sendwarm(){
        
        NotificationManager noteMng = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        //创建一个意图,确定点击状态栏后跳转的页面
        Intent i = new Intent();
//        i.setClassName(this, "com.android.mms.ui.ConversationList");
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0);
        Notification.Builder builder = new Notification.Builder(this).setTicker("您有一条新短信")
                .setSmallIcon(R.drawable.sym_action_email);
        note = builder.setContentIntent(pendingIntent).setContentTitle(str_number).setContentText(str_body).build();
        //默认提示音
        note.defaults |= Notification.DEFAULT_SOUND;
        //默认震动模式
        note.defaults |= Notification.DEFAULT_VIBRATE;
        //默认LED提示模式
        note.defaults |= Notification.DEFAULT_LIGHTS;
        //重复上面的各种提示模式
//        note.flags |= Notification.FLAG_INSISTENT;
        //点击查看后跳转
        note.flags |= Notification.FLAG_AUTO_CANCEL;
        //状态栏无法清除
        note.flags |= Notification.FLAG_NO_CLEAR;
        
        
        noteMng.notify(110, note);
        
        
        
        
        
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        
        str_number = et_number.getText().toString().trim();
        str_body = et_body.getText().toString().trim();
        time = Integer.valueOf(et_time.getText().toString().trim()) * 1000;
        
        switch(v.getId()){
        
        case R.id.bt:
            new Thread(){
                public void run(){
                    try {
                        //延迟20秒
                        Thread.sleep(time);
                        
                        //创建一个接收对象
                        ContentResolver resolver = getContentResolver();
                        Uri uri = Uri.parse("content://sms");
                        ContentValues values = new ContentValues();
                        values.put("address", str_number);
                        values.put("type", 1);
                        values.put("date", System.currentTimeMillis());
                        values.put("service_center", "+8613800270503");
                        values.put("body", str_body);
                        resolver.insert(uri, values);
                        //消息栏提示
                        sendwarm();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    
                }
            }.start();
            //关闭页面
            this.finish();
            break;
        }
        
            
            
    }

}

 

<?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="wrap_content"
            android:textSize="20sp"
            android:layout_marginLeft="5dp"
            android:text="发送号码"
            />
        <EditText 
            android:id="@+id/et_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入电话号码"
            android:inputType="text"
            />
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
          android:orientation="horizontal"
        >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:layout_marginLeft="5dp"
            android:text="延时时间"
            />
        <EditText 
            android:id="@+id/et_time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="时间以秒为单位"
            android:inputType="number"
            />
    </LinearLayout>
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="短信内容"
        android:layout_marginLeft="5dp"
        />
    
    <EditText 
        android:id="@+id/et_body"
        android:layout_weight="200"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="textMultiLine"
        />
    
    <Button 
        android:id="@+id/bt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="运行"
        />

</LinearLayout>

http://www.cnblogs.com/qingriye/p/4767063.html

 

posted @ 2015-09-06 23:03  沧海一滴  阅读(1157)  评论(0编辑  收藏  举报