How to write SMS and call log into DB of stock ROM android


This is a test application,I built this application to write data into SMS and call logs DB system on stock ROM android.

here the complete project: Download PRJ
here the sample code with which write the data into DB sms/calllogs:

Button btnInsertSms = (Button) findViewById(R.id.btn_recordsms);
btnInsertSms.setOnClickListener(new OnClickListener() {
	public void onClick(View v) {
		
		String strAnddress = edtAnddress.getText().toString();
		String strBody = edtBody.getText().toString();
		
		ContentValues values = new ContentValues();
		values.put("address", strAnddress);
		values.put("body", strBody);
		getContentResolver().insert(Uri.parse("content://sms"), values);
	}
});


Button btnInsertCallLog = (Button) findViewById(R.id.btn_callrecord);
btnInsertCallLog.setOnClickListener(new OnClickListener() {
	public void onClick(View v) {
		
		String strAnddress = edtCallAnddress.getText().toString();
		String strDuration = edtCallDuration.getText().toString();
		int type=0;
		switch (spnTypeCall.getSelectedItemPosition())
		{
			case 0:
				type= CallLog.Calls.INCOMING_TYPE;
				break;
			case 1:
				type=CallLog.Calls.OUTGOING_TYPE;
				break;
			case 2:
				type=CallLog.Calls.MISSED_TYPE;
				break;
		}
		
		ContentValues values = new ContentValues();
		values.put(CallLog.Calls.NUMBER,strAnddress);
		values.put(CallLog.Calls.DATE, System.currentTimeMillis());
		values.put(CallLog.Calls.DURATION,strDuration);
		values.put(CallLog.Calls.TYPE,type);
		values.put(CallLog.Calls.NEW, 1);
		values.put(CallLog.Calls.CACHED_NAME,"");
		values.put(CallLog.Calls.CACHED_NUMBER_TYPE,0);
		values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");

		
		
		
		getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);
	}
});

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...