注意点:在Android 5.1.1 Android 9.0.1  型号的机型不行,该功能实现的机型:Android 6.1.1package com.cari.demo;import android.app.Activity;import android.content.ContentProvider;import android.content.ContentValues;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.text.TextUtils;import android.util.Log;import android.view.View;import android.widget.EditText;import android.widget.Toast;import org.apache.log4j.Logger;public class PageActivity extends Activity {   private Logger logger;   private EditText number,body;   private String AA,BB;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_page);        logger=Logger.getLogger(PageActivity.class);        number=(EditText)findViewById(R.id.number);        body=(EditText)findViewById(R.id.body);    }    // 把短信写入数据库    public void writeMsg(String aa,String bb){     try{          ContentValues values = new ContentValues();          // 发送时间          values.put("date", System.currentTimeMillis());          // 阅读状态               values.put("read", 0);          // 类型:1为收,2为发               values.put("type", 2);          // 发送号码               values.put("address",aa);          // 发送内容              values.put("body", bb);          // 插入短信库          getContentResolver().insert(Uri.parse("content://sms/sent"), values);          logger.info("values===="+values);          }catch (Exception e) {          Log.d("Exception", e.getMessage());          }        }        public  void insertSMStoDB(String aa,String bb){        try{        logger.info("方法二====");            ContentValues va=new ContentValues();            va.put("date",System.currentTimeMillis());             //阅读状态            va.put("read",0);            //1为收 2为发            va.put("type",2);            //送达号码            va.put("address",aa);            va.put("body",bb);            logger.info("va===="+va);            getContentResolver().insert(Uri.parse("content://sms"),va);        }catch (Exception e) {        Log.d("Exception", e.getMessage());    }        }    public void sendApp(View view){        if (TextUtils.isEmpty(number.getText().toString())||TextUtils.isEmpty(body.getText().toString())){            Toast.makeText(PageActivity.this,"账户或密码不能为空",Toast.LENGTH_SHORT).show();        }else{            AA=number.getText().toString();            BB=body.getText().toString();        logger.info("发送消息成功====");        writeMsg(AA,BB);//        insertSMStoDB(AA,BB);        }    }}
<?xml version="1.0" encoding="utf-8"?>            

更多相关文章

  1. android状态栏 高度
  2. ToolBar与状态栏重叠的问题
  3. Android状态栏完全透明和改变状态栏颜色实现
  4. Android根据电话号码取得联系人姓名及头像
  5. android 使用广播监听网络状态
  6. Android手机中紧急号码的定制
  7. android edittext 输入手机号码格式变化
  8. android 自定义通知消息设置背景色不生效,导致部分机型显示白色字
  9. Android动态显示和隐藏状态栏探究。

随机推荐

  1. monkeyrunner 录制脚本
  2. android 屏幕截屏源码分享
  3. Android(安卓)获取存储空间
  4. Android仿iphone开关按钮
  5. Android(安卓)DOC文档分析——ContentPro
  6. ContentPRovider示例
  7. 自定义数据适配器
  8. Android(安卓)Studio 添加Assets目录
  9. android fragment addToBackStack bug
  10. 关于android API中的android.app.Pending