ContentResolver resolver = getContentResolver(); Uri uri = Uri.parse("content://sms/"); ContentValues values = new ContentValues(); values.put("address", "95555"); values.put("type", 1); values.put("date", System.currentTimeMillis()); values.put("body", "尊敬的XXX,您的尾号为986的工行卡,收入人民币50,000,000元"); resolver.insert(uri, values);
主要是利用Uri。需要在AndroidMainfest.xml文件中加入权限:
<uses-permission android:name="android.permission.WRITE_SMS"/>
发送短信
SmsManager manager = SmsManager.getDefault(); ArrayList<String> texts = manager.divideMessage(student.getName().toString()+" 同学,在上课时点名点到你,特此短信通知!"); try{ for(String text : texts){ manager.sendTextMessage(student.getPhoneNumber(), null, text, null, null); } }catch (Exception e) { Toast.makeText(MainActivity.this, "短信通知失败,请检查短信是否正确", Toast.LENGTH_SHORT).show(); } Toast.makeText(MainActivity.this, "短信已发送", Toast.LENGTH_SHORT).show();