﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog of krishnaraj varma</title>
	<atom:link href="http://www.krvarma.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krvarma.com</link>
	<description>a simple blog</description>
	<lastBuildDate>Sun, 29 Aug 2010 16:54:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Detecting incoming and outgoing calls in Android</title>
		<link>http://www.krvarma.com/posts/android/detecting-incoming-and-outgoing-calls-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/detecting-incoming-and-outgoing-calls-in-android/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 16:54:48 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=633</guid>
		<description><![CDATA[Download In one of my project, I wanted to detect incoming and outgoing calls. I used BroadcastReceiver with action android.intent.action.NEW_OUTGOING_CALL and android.intent.action.PHONE_STATE. The android.intent.action.NEW_OUTGOING_CALL will be broadcasted when an outgoing call is initiated. The receiving intent will have an extra string variable Intent.EXTRA_PHONE_NUMBER which contains the outgoing number. This requires the permission android.permission.PROCESS_OUTGOING_CALLS. To detect [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=22" title="Version1.0 downloaded 25 times" >Detect Calls Sample (25)</a></p>
<p>In one of my project, I wanted to detect incoming and outgoing calls. I used BroadcastReceiver with action <code>android.intent.action.NEW_OUTGOING_CALL</code> and <code>android.intent.action.PHONE_STATE</code>.</p>
<p>The <code>android.intent.action.NEW_OUTGOING_CALL</code> will be broadcasted when an outgoing call is initiated. The receiving intent will have an extra string variable <code>Intent.EXTRA_PHONE_NUMBER</code> which contains the outgoing number. This requires the permission <code>android.permission.PROCESS_OUTGOING_CALLS</code>.</p>
<p>To detect the incoming call, we register a BroadcastReceiver for the action <code>android.intent.action.PHONE_STATE</code>. This will be broadcasted when there is a change in phone state. The receiving intent will have an extra string variable <code>TelephonyManager.EXTRA_STATE</code> which describes the phone state. If this state is <code>TelephonyManager.EXTRA_STATE_RINGING</code> then there will be another extra string variable <code>TelephonyManager.EXTRA_INCOMING_NUMBER</code>. This variable contains the incoming phone number. Note that this variable will not be present when the state is not <code>TelephonyManager.EXTRA_STATE_RINGING</code>. </p>
<p>The sample application is a simple one just for demonstration. The application registers for these actions and when the calls are detected it just displays a toast.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/detecting-incoming-and-outgoing-calls-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android network connectivity BroadcastReceiver</title>
		<link>http://www.krvarma.com/posts/android/android-network-connectivity-broadcastreceiver/</link>
		<comments>http://www.krvarma.com/posts/android/android-network-connectivity-broadcastreceiver/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 17:41:36 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=612</guid>
		<description><![CDATA[Download Most of the time we need to connect to internet to download or upload data. If the downloading or uploading is a lengthy process, we need to know when the network connected or gone, so that we can temporarily pause the uploading or downloading and resume once the connection is established. In Android we [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=21" title="Version1.0 downloaded 19 times" >Connectivity Sample (19)</a></p>
<p>Most of the time we need to connect to internet to download or upload data. If the downloading or uploading is a lengthy process, we need to know when the network connected or gone, so that we can temporarily pause the uploading or downloading and resume once the connection is established. In Android we can register a <code>BroadcastReciver</code> with action <code>ConnectivityManager.CONNECTIVITY_ACTION</code>. System will broadcast this whenever a change in the network connectivity occurs.</p>
<p>Information regarding the connection will be there in the receiving intent. Some of them are:</p>
<pre language="java">ConnectivityManager.EXTRA_EXTRA_INFO
A string value indicating the network state.

ConnectivityManager.EXTRA_IS_FAILOVER
A boolean value indicates whether the connection manager is failing over or not.

ConnectivityManager.EXTRA_NETWORK_INFO
A NetworkInfo class with network information.

ConnectivityManager.EXTRA_NO_CONNECTIVITY
A boolean value indicating there is no internet connectivity.

ConnectivityManager.EXTRA_OTHER_NETWORK_INFO
A NetworkInfo class with network information of another network that may be connected.

ConnectivityManager.EXTRA_REASON
A String value about the reason of the connection failure.</pre>
<p>You can check either <code>ConnectivityManager.EXTRA_EXTRA_INFO</code> or NetworkInfo.State from the <code>ConnectivityManager.EXTRA_NETWORK_INFO key</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/android-network-connectivity-broadcastreceiver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android sample application: Simple logcat viewer</title>
		<link>http://www.krvarma.com/posts/android/simple-android-logcat-viewer/</link>
		<comments>http://www.krvarma.com/posts/android/simple-android-logcat-viewer/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:04:55 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=604</guid>
		<description><![CDATA[Download Here is a sample application to view logcat messages on device. The application runs the command “logcat” using Runtime class, reads each log string and adds the string to a list view. Whenever you click on an item, an alert box is displayed with the corresponding log message.]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=20" title="Version1.0 downloaded 21 times" >Log Viewer Sample (21)</a></p>
<p>Here is a sample application to view logcat messages on device. The application runs the command “logcat” using <code>Runtime</code> class, reads each log string and adds the string to a list view. Whenever you click on an item, an alert box is displayed with the corresponding log message.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/simple-android-logcat-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android sample application: Simple RSS reader</title>
		<link>http://www.krvarma.com/posts/android/android-sample-application-simple-rss-reader/</link>
		<comments>http://www.krvarma.com/posts/android/android-sample-application-simple-rss-reader/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 16:24:12 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=592</guid>
		<description><![CDATA[Download Just for fun and time-pass I created a sample RSS reader application based on this article. I think it is better to share it here. Point of Interest: Downloading XML data from Internet, XML parsing, AsyncTask.]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=19" title="Version1.0 downloaded 21 times" >RSS Reader (21)</a></p>
<p>Just for fun and time-pass I created a sample RSS reader application based on <a href="http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/" target="_blank">this article</a>. I think it is better to share it here.</p>
<p class="note"><strong>Point of Interest</strong>: Downloading XML data from Internet, XML parsing, AsyncTask.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/android-sample-application-simple-rss-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming camera in Android</title>
		<link>http://www.krvarma.com/posts/android/programming-camera-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/programming-camera-in-android/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 19:29:55 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=585</guid>
		<description><![CDATA[Download Almost all mobile phones have a built in digital camera. Android phones are no exception. In Android device, to access the camera hardware we use Camera class along with SurfaceView. The Camera class let you change the settings, preview and take still pictures. The SurfaceView class is used to show the preview to the [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=18" title="Version1.0 downloaded 75 times" >Camera Demo (75)</a></p>
<p>Almost all mobile phones have a built in digital camera. Android phones are no exception. In Android device, to access the camera hardware we use <code>Camera</code> class along with <code>SurfaceView</code>. </p>
<p>The Camera class let you change the settings, preview and take still pictures. The SurfaceView class is used to show the preview to the user. To use the camera feature you should have the android.permission.CAMERA permission. </p>
<p>First we create a SurfaceView to show the live preview. The SurfaceView class holds the surface to draw. We use the interface SurfaceHolder to access the underlying surface. We implement the callback interface SurfaceHolfer.Callback and add this to the SurfaceHolder using SurfaceHolder.addCallback method. The SurfaceHolfer.Callback interface has three methods:</p>
<pre language="java">abstract void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
abstract void surfaceCreated(SurfaceHolder holder)
abstract void surfaceDestroyed(SurfaceHolder holder)</pre>
<p>The surfaceCreated method will be called after the surface is created, surfaceChanged will be after any changes have been made to the surface and surfaceDestroyed will be called after the surface is destroyed. </p>
<p>To find more about the SurfaceView and SurfaceHolder interface refer to the Google documentation.</p>
<p>Once our surface is created we open the Camera using Camera.open() method. After opening the camera, we set the live preview surface using <code>setPreviewDisplay()</code> method of the Camera class. We open and set the preview surface once the <code>surfaceCreated()</code> method is called because at this point the surface will be created and initialized properly.</p>
<p>Now we have to set the appropriate parameters to start the camera using the Camera.Parameters class. We can get the current camera parameter using the <code>getParameters()</code> method of the Camera class. We set the camera parameter once the <code>surfaceChaneged()</code> method is called. Once we set all the camera parameters we can start preview using <code>Camera.startPreview()</code> method. This will start the live preview.</p>
<p>The Camera class uses different callback interface to report different events to the application. The following callback interfaces are used to notify the events;</p>
<pre language="java">Camera.AutoFocusCallback
Camera.ErrorCallback
Camera.PictureCallback
Camera.PreviewCallback
Camera.ShutterCallback</pre>
<p>The <code>Camera.AutoFocusCallback</code> interface is used to notify the completion of auto focus. Note that all devices may not have auto-focus feature. The <code>onAutoFocus()</code> will be called once the auto focus in finished. We use <code>Camera.autoFocus()</code> method to start the auto focus.</p>
<p>The <code>Camera.ErrorCallback</code> interface is used to notify when an error occurred. The <code>onError()</code> method will be called if an error occurred during the camera operation.</p>
<p>The <code>Camera.PictureCallback</code> interface is used to supply the image data after the picture is taken. The <code>onPictureTaken()</code> method will be called once the data is available. The format of the data depends on the current camera picture format which can be set using Camera.Parameters class.</p>
<p>The <code>Camera.PreviewCallback</code> interface is used to notify the supply the current preview frame. The <code>onPreviewFrame()</code> method will be called when the preview frame is available. Again the format of the data depends on the current camera picture format.</p>
<p>The <code>Camera.ShutterCallback</code> interface is to notify when the picture is captured from the camera. The <code>onShutter()</code> method will be called once the picture is taken from the camera.</p>
<p>To take a still picture, we use the method <code>Camera.takePicture()</code> The takePicture() method has three parameters. First one is a <code>Camera.ShutterCallback</code> interface to notify when the picture is captured from the camera. Second one is <code>Camera.PictureCallback</code> interface to notify when raw data is available from the camera. The third one is another <code>Camera.PictureCallback</code> interface when the JPEG data is available from the device.</p>
<p>In API version 5 or above there is another variant of <code>takePicture()</code> method. This method accepts 4 parameters. The first and second are same as the previous one. The third is the <code>Camera.PictureCallback</code> interface which is used to notify when completely scaled postview image is available. The forth one is the same as the third parameter in the first variant.</p>
<p>The data will be supplied to the calling application, the application can use this data for post processing or saving to a file.</p>
<p>In API version 8 or above, we can use the method <code>Camera.setDisplayOrientation()</code> method to set the orientation of the display. This is used by portrait applications to correctly display the live preview. In versions prior to 8, we can safely use the landscape mode to correctly display the preview.</p>
<p>The sample application displays the live preview. When the take picture button is clicked the image is saved to sdcard using time as the filename.</p>
<p>Happy Camera Coding <img src='http://www.krvarma.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/programming-camera-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launching external applications in Android</title>
		<link>http://www.krvarma.com/posts/android/launching-external-applications-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/launching-external-applications-in-android/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 18:15:10 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=547</guid>
		<description><![CDATA[Download In Android we use intent to start an activity, start a service, send broadcasts, etc. Intent is used for late runtime binding of applications. In Android intent represents the action to be performed. There are two primary information in an intent, they are action and data. Action attribute represents the action to be performed [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=17" title="Version1.0 downloaded 37 times" >Application Launcher Source Code (37)</a></p>
<p>In Android we use intent to start an activity, start a service, send broadcasts, etc. Intent is used for late runtime binding of applications. In Android intent represents the action to be performed. There are two primary information in an intent, they are <strong>action</strong> and <strong>data</strong>. Action attribute represents the action to be performed such as edit, view, dial, etc. The data attribute is the data to be operated on. Some of the common actions are <code>ACTION_VIEW, ACTION_DIAL, ACTION_EDIT, ACTION_PICK, ACTION_SEND, ACTION_SEARCH, ACTION_CALL</code>, etc. The following code snippets show some of the examples:</p>
<h4>Start the email client</h4>
<pre language="java">final String[] addressList = new String[] { toAddress };

final Intent email_intent = new Intent(android.content.Intent.ACTION_SEND);
email_intent.setType("message/rfc822");
email_intent.putExtra(android.content.Intent.EXTRA_EMAIL, addressList);
email_intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sample mail");
email_intent.putExtra(android.content.Intent.EXTRA_TEXT, "Sample mail for testing purpose");

startActivity(Intent.createChooser(email_intent, "Send mail..."));</pre>
<h4>Dial a number</h4>
<pre language="java">// needs permission android.permission.CALL_PHONE
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel://123456789"));

startActivity(intent);</pre>
<h4>Start a web search</h4>
<pre language="java">Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);

intent.putExtra(SearchManager.QUERY, "Krishnaraj Varma");

startActivity(intent);</pre>
<p>For a more detailed information about intent and intent action follow <a href="http://developer.android.com/reference/android/content/Intent.html" target="_blank">this link</a></p>
<p>There is another method to start an application using <code>PackageManager</code> class. This class has a method <code>getLaunchIntentForPackage</code> which will return the LAUNCHER intent of the specified package or null if not found. We can use this returned intent to start the application. The following code snippet starts the example application of this article:</p>
<pre language="java">PackageManager packageManager = getPackageManager();
String packageName = "com.varma.samples.applauncher";

try
{
	Intent intent = packageManager.getLaunchIntentForPackage(packageName);

	if(null != intent)
	{
		startActivity(intent);
	}

}
catch (NameNotFoundException e)
{
	e.printStackTrace();
}
catch (ActivityNotFoundException e)
{
	e.printStackTrace();
}</pre>
<p>To enumerate all the installed application packages, we can use <code>getInstalledApplications</code> method of the <code>PackageManager</code> class. This method returns a list of <code>ApplicationInfo</code> class. The <code>ApplicationInfo</code> class contains information regarding and application such as package name, label, icon, etc. This information comes from the <code>AndroidManifest.xml</code> file of the particular application.</p>
<p>The example application lists all the installed applications in a list view and when you click on an item, the application will be launched if a LAUNCHER intent is found.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/launching-external-applications-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using time zones in Android</title>
		<link>http://www.krvarma.com/posts/android/using-time-zones-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/using-time-zones-in-android/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 20:58:15 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=516</guid>
		<description><![CDATA[Download Recently in one of my project, time has to be displayed in different time zone. I used the class SimpleDateFormat class to convert and format the local time. This class has one convenient method setTimeZone, which converts the location time to the given time zone while formatting. The following code snippet converts the local [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=16" title="Version1.0 downloaded 29 times" >TimeZone sample (29)</a></p>
<p>Recently in one of my project, time has to be displayed in different time zone. I used the class <strong><code>SimpleDateFormat</code></strong> class to convert and format the local time. This class has one convenient method <strong><code>setTimeZone</code></strong>, which converts the location time to the given time zone while formatting. The following code snippet converts the local time to another time zone:</p>
<pre language="java">SimpleDateFormat format = new SimpleDateFormat("EEE, MMM d, yyyy h:mm a");
format.setTimeZone(timezone);
format.format(new Date());</pre>
<p>If you want to enumerate all the time zones, you can use the method <strong><code>getAvailableIDs</code></strong> of the <strong><code>TimeZone</code></strong> class. The method returns an array of string which contains all the timezone ids. The sample application lists all the time zones and the corresponding time. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/using-time-zones-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking GPS is enabled or not in Android</title>
		<link>http://www.krvarma.com/posts/android/checking-gps-is-enabled-or-not-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/checking-gps-is-enabled-or-not-in-android/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 17:48:52 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=506</guid>
		<description><![CDATA[Download While searching for how to programmatically find whether GPS is enabled or not in device, I found this excellent answer and created a sample application based on it. I think it is better to share it here.]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=15" title="Version1.0 downloaded 51 times" >CheckGPS (51)</a></p>
<p>While searching for how to programmatically find whether GPS is enabled or not in device, I found this <a href="http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled" target="_blank">excellent answer</a> and created a sample application based on it. I think it is better to share it here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/checking-gps-is-enabled-or-not-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Text to Speech in Android</title>
		<link>http://www.krvarma.com/posts/android/using-text-to-speech-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/using-text-to-speech-in-android/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 16:52:49 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=497</guid>
		<description><![CDATA[Download Android supports TextToSpeech (TTS) from version 1.6 onwards. The Android TextToSpeech can speak different languages such as English, German, French, etc&#8230;, but we have to download the language resource files first before using it. We can install the language files by launching Intent with action set to TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA. The following code launches the installation [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=14" title="Version1.0 downloaded 50 times" >TTS Engine Sample (50)</a></p>
<p>Android supports TextToSpeech (TTS) from version 1.6 onwards. The Android TextToSpeech can speak different languages such as English, German, French, etc&#8230;, but we have to download the language resource files first before using it. We can install the language files by launching Intent with action set to TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA.  The following code launches the installation of language data:</p>
<pre language="java">Intent intent = new Intent();
intent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(intent);</pre>
<p>The class <strong>android.speech.tts.TextToSpeech</strong> is used for TTS in Android. The constructor has two parameters, <strong>Context</strong> and <strong>TextToSpeech.OnInitListener</strong>. The TextToSpeech.OnInitListener’s onInit method will be called when the TTS engine is initialized. The status is passed to the <strong>onInit(int status)</strong> method. The value TextToSpeech.SUCCESS indicates success and TextToSpeech.ERROR indicates error.</p>
<p>Once it is successfully initialized we can use the speak method to start speaking. The syntax of speak method is:</p>
<pre language="java"> public int speak(String text, int queueMode, HashMap<String, String> params)</pre>
<p>The first parameter is the text to speak, second is parameter is the queuing mode. This parameter can be either TextToSpeech.QUEUE_ADD or TextToSpeech.QUEUE_FLUSH. The value TextToSpeech.QUEUE_FLUSH tells the system to drop all entries in the queue and start with the new text. TextToSpeech.QUEUE_ADD tells the system to append the new text the queue. The third parameter is a HashMap<String, String> The key can have values TextToSpeech.Engine.KEY_PARAM_STREAM or TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID. If the key is TextToSpeech.Engine.KEY_PARAM_STREAM, then the value is one of the AudioManger’s stream types. When you specify one of these values, the TextToSpeech engine will use the settings of that particular stream to speak the text. Some of the possible values are:</p>
<pre language="java">String.valueOf(AudioManager.STREAM_ALARM)
String.valueOf(AudioManager.STREAM_MUSIC)
String.valueOf(AudioManager.STREAM_RING)</pre>
<p>If the key is TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, then the value is a user defined string id. This can be used to check whether the TTS engine finished speaking the text or not. When the TTS engine finished speaking the text, the <strong>TextToSpeech.OnUtteranceCompletedListener</strong>’s <strong>onUtteranceCompleted</strong> method will be called. This technique is used in the sample application. For more information refer to the source code of the sample.</p>
<p>We can change the TTS engine’s language by using the method <strong>setLocale(Locale loc)</strong>. The parameter loc specifies the Locale corresponds to desired language. </p>
<p>The speech rate can be set by using the method <strong>setSpeechRate(float speechRate)</strong>. The parameter speechRate specifies the rate of the speech. 1 is normal rate. Lower values slow the speech rate and higher values increases the rate. </p>
<p>To change the pitch we use setPitch(float pitch). The parameter pitch specifies the pitch to use. 1 means normal, less than 1 lowers the tone and greater that 1 increases the tone.</p>
<p>I hope this gives you an introduction to the TTS in Android, for more detailed information refer to <a href="http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html" target="_blank">this excellent article</a>.</p>
<p>Happy TTS coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/using-text-to-speech-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting IP address of the device in Android</title>
		<link>http://www.krvarma.com/posts/android/getting-ip-address-of-the-device-in-android/</link>
		<comments>http://www.krvarma.com/posts/android/getting-ip-address-of-the-device-in-android/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 10:27:35 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=489</guid>
		<description><![CDATA[Download For one of my project I need to get the IP address of the device, I searched a lot and found this link. The method is to enumerate all network interfaces and find the IP address if it is not loop-back adapter. This will give the IP address if you are connected to a [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Download <a class="downloadlink" href="http://www.krvarma.com/wp-content/plugins/download-monitor/download.php?id=13" title="Version1.0 downloaded 54 times" >IP Address Sample (54)</a></p>
<p>For one of my project I need to get the IP address of the device, I searched a lot and found <a href="http://www.droidnova.com/get-the-ip-address-of-your-device,304.html" target="_blank">this link</a>. </p>
<p>The method is to enumerate all network interfaces and find the IP address if it is not loop-back adapter. This will give the IP address if you are connected to a network (WiFi or Cellular). </p>
<p>You can also use the <strong>WifiManger</strong> to get he IP address if you are connected to WiFi network. The following code retrieves the WiFi IP address:</p>
<pre language="java">WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();</pre>
<p>Note that the <b>getIpAddress</b> returns an integer value. To convert to readable format we can use the following code:</p>
<pre language="java">String.format("%d.%d.%d.%d",
(ipAddress &#038; 0xff),
(ipAddress >> 8 &#038; 0xff),
(ipAddress >> 16 &#038; 0xff),
(ipAddress >> 24 &#038; 0xff))</pre>
<p><strong>Note</strong>: To use the first method you need the <strong>android.permission.INTERNET</strong> permission, otherwise it will throw unknown error. For the second method you need <strong>android.permission.ACCESS_WIFI_STATE</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/posts/android/getting-ip-address-of-the-device-in-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
