Content://sms

简介: package com.example.sms; import android.app.Activity; import android.app.Notification; import android.

 

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

 

相关文章
|
4月前
|
XML JSON 编解码
HTTP Content-Type 类型解析
【1月更文挑战第10天】HTTP Content-Type 类型解析
|
7月前
Android-async-http 添加token get方法报错 No valid URI scheme was provided
Android-async-http 添加token get方法报错 No valid URI scheme was provided
|
11月前
|
XML JSON 前端开发
详解Http的Content-Type
1.概述 HTTP(HyperText Transfer Protocol),超文本传输协议。超文本(Hypertext)是一种结构化的文本,其中包含了超链接(Hyperlink)的能力,通过超链接可以在不同文档之间创建关联和跳转。 传统的文本是线性的,按照一定的顺序排列的,而超文本则打破了线性结构,允许文本中的某些词、短语或图像与其他文档或资源之间建立关联。这些关联通过超链接来实现,用户可以点击超链接来跳转到其他相关的文档、网页、图片、视频或其他媒体资源。
196 1
|
JavaScript 网络安全
Mixed Content: The page at ‘<URL>‘ was loaded over HTTPS, but requested an insecure frame ‘<URL>‘...
Mixed Content: The page at ‘<URL>‘ was loaded over HTTPS, but requested an insecure frame ‘<URL>‘...
662 0
|
XML JSON JavaScript
二、HTTP Content-Type详解
二、HTTP Content-Type详解
263 1
|
XML 数据格式 前端开发
|
Android开发 机器学习/深度学习
|
Java 数据库 Android开发
|
XML JSON Android开发
Android http Request / Response ContentType
客户端在进行http请求服务器的时候,需要告诉服务器请求的类型,服务器在返回给客户端的数据的时候,也需要告诉客户端返回数据的类型。 这个类型就是  ContentType  ,不同的ContentType 会影响客户端/服务器所看到的效果。
1082 0