Tag Archives: ContentValues

Event Handling using DataBinding in Android.

By | February 3, 2017

Using data binding, you can also handle events right from the layout xml using either Method references, or Listener bindings. For this we can create a seperate Class named “MyHandler”. Event Handler Class MyHandler.java [java] package binding_demo.coderzheaven.com.bindingdemo; import android.util.Log; import android.view.View; import android.widget.Button; import static android.content.ContentValues.TAG; public class MyHandler { public void onClick(View view){ Log.i(TAG, "onClick"); ((Button) view).setText("Clicked");… Read More »

How to write a custom content provider in android? with a sample application using our own custom content provider.

By | September 22, 2013

Hello all we all know what are content providers right? Those who are unaware of content providers please visit this link http://developer.android.com/guide/topics/providers/content-providers.html In a breif content Providers are Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data… Read More »

How to add a new contact programmatically in android?

By | June 18, 2012

We all know how to add a new contact to our android devices without programming right. OK that’s a normal man’s use. But what from a programmer’s view. This is the sample java code that helps you to add contact programatically. [java] package com.coderzheaven.pack; import java.util.ArrayList; import android.app.Activity; import android.content.ContentProviderOperation; import android.content.ContentValues; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract;… Read More »

How to save CheckBox values in SQlite Database and Load it later?

By | March 13, 2012

Hello…….. This post is just a simple demonstration to show a way to store a checkbox value in a database and reload it. Here I am storing only a value of a single checkbox and reloading it. But you can make changes in the code to save the id and value of the checkbox in the database and… Read More »

How to save data or score in Android Cocos2D?

By | January 21, 2012

Hello Friends Today I will show you how to save data in cocos2D android in a database and reload it when the game starts. This has been always a problem withe game developers for cocos2D android. I will show you a way to save almost any number of data in a database using SQlite in android. Check these… Read More »

How to set ringtone in android programmatically?

By | October 5, 2010

This code will set your ringtone for ANDROID. [java] String filepath ="/sdcard/myring.mp3"; File ringtoneFile = new File(filepath); [/java] To set a ringtone you have to add it to the database. otherwise it will not be set also gives no error also. [java] ContentValues content = new ContentValues(); content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath()); content.put(MediaStore.MediaColumns.TITLE, "test"); content.put(MediaStore.MediaColumns.SIZE, 215454); content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*"); content.put(MediaStore.Audio.Media.ARTIST, "artist"); content.put(MediaStore.Audio.Media.DURATION, 230);… Read More »

How to capture audio in an android application?

By | October 5, 2010

This code snippet captures audio from a given source and saves it to a file with android.media.MediaRecorder. [java] /* Create a MediaRecorder */ recorder = new MediaRecorder(); /* ContentValues include title, timestamp, mime type */ ContentValues values = new ContentValues(3); values.put(MediaStore.MediaColumns.TITLE, SOME_NAME_HERE); values.put(MediaStore.MediaColumns.TIMESTAMP, System.currentTimeMillis()); values.put(MediaStore.MediaColumns.MIME_TYPE, recorder.getMimeContentType()); /* Create entry in the content database */ ContentResolver contentResolver = new… Read More »