短信是手機常見的功能,本文就以實例形式講述了Android實現(xiàn)將已發(fā)送的短信寫入短信數(shù)據(jù)庫的方法。分享給大家供大家參考之用。具體如下:
一般來說,把短信發(fā)送出去以后,需要把已發(fā)送的短信寫入短信數(shù)據(jù)庫。短信數(shù)據(jù)庫有多個Uri,其中已發(fā)送的Uri是content://sms/sent。
具體功能代碼如下:
// 把短信寫入數(shù)據(jù)庫public void writeMsg(){ try{ ContentValues values = new ContentValues(); // 發(fā)送時間 values.put("date", System.currentTimeMillis()); // 閱讀狀態(tài) values.put("read", 0); // 類型:1為收,2為發(fā) values.put("type", 2); // 發(fā)送號碼 values.put("address",smsWidget.str_number); // 發(fā)送內容 values.put("body", content); // 插入短信庫 getContentResolver().insert(Uri.parse("content://sms/sent"), values); }catch (Exception e) { Log.d("Exception", e.getMessage()); }}定義一個新的ContentValues,將短信的相關數(shù)據(jù)put進去,然后getContentResolver().insert()就可以了。
希望本文所述對大家的Android程序設計有所幫助。
新聞熱點
疑難解答
圖片精選