Tag Archives: Logcat

How to read a serialized object from a file in the raw folder in android?

By | July 30, 2012

In my previous post I showed how to serialize an object and save it in sdcard in a file and retrieve it. Pull out the file from the sdcard and then create a folder named “raw” inside the “res” folder and copy it. This example shows how to retreive it when it is in the res/raw folder. Here… Read More »

JSON IN ANDROID.

By | April 26, 2012

Complex JSON String parsing in ANDROID http://www.coderzheaven.com/2011/06/10/complex-json-string-parsing-in-android/ Parsing JSON Object in ANDROID. http://www.coderzheaven.com/2011/06/09/parsing-json-objects-in-android/

How to Sort a String array in Android.

By | February 25, 2012

Hello all…. This is a simple example showing how to sort a string array which is a arraylist in android. we sort the array using the “Collections” class in android. Here is a simple example [java] package com.coderzheaven.pack; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import android.app.Activity; import android.os.Bundle; public class SortingStringsDemo extends Activity { @Override public… Read More »

How to encrypt a string in Android Using Base64?

By | January 9, 2012

[java] package com.coderzheaven.encryptstring; import android.annotation.SuppressLint; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Base64; @SuppressLint({ "WorldReadableFiles", "WorldWriteableFiles" }) public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); saveText("CoderzHeaven"); System.out.println(getText()); } public void saveText(String text) { SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE); SharedPreferences.Editor editor = myPrefs.edit(); text = Base64.encodeToString(text.getBytes(), Base64.DEFAULT); editor.putString("some_text", text); editor.commit(); } public String… Read More »

How to create a MD5 hash of a word in android?

By | September 3, 2011

This is one of the most useful things in android. We can use the MD5 algorithm to create a hash of any string we want. Here is the code for doing that. Check the LogCat for output. [java] package pack.coderzheaven; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import android.app.Activity; import android.os.Bundle; public class MD5Demo extends Activity { @Override public… Read More »

How to get the current progress on your SeekBar in android?

By | August 11, 2011

I have already shown how to use seekBar in android. This simple snippet helps you to get the current progress in the seekbar. It’s same code from this post, only thing is I added the getProgress method. [java] package com.coderzheaven; import android.app.Activity; import android.os.Bundle; import android.widget.SeekBar; import android.widget.TextView; public class SeekBarDemo extends Activity implements SeekBar.OnSeekBarChangeListener { SeekBar mSeekBar;… Read More »

How to read Logcat contents programmatically in Android?

By | July 16, 2011

This is an example to read Logcat contents programmatically in Android. Normal developers won’t need this, but still it is a good thing to know how to do it. [java] package pack.coderzheaven; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ReadLogDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);… Read More »

Get All Details from Contacts in ANDROID.

By | June 13, 2011

Hi all.. In today’s post I will show you how to get all information from the ANDROID Contacts programatically. Just copy and paste this code to your mail java file and check the Logcat for output. [java] package pack.coderzheaven; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; public class GetContactsDemo extends Activity { /** Called when… Read More »

Complex JSON String parsing in ANDROID

By | June 10, 2011

Hello all….. In the previous post I have shown you how to parse a Simple JSON String in ANDROID. In today’s tutorial I will show you how to parse a complex JSON String. Take a look at the example Here the JSON String used is [java] "{"menu": " "{"id": " ""file", "value": "File", "popup": " "{ "menuitem": [… Read More »

Parsing JSON Object in ANDROID.

By | June 9, 2011

JSON are alternative to XML and easy to understand than XML. As other languages Java also supports JSON parsing. Here is a simple example of JSON parsing in ANDROID. This is the JSON String that I am going to parse. [java] {"A": { "A1":"A1_value" ,"A2":"A2_value","sub": { "sub1":[ {"sub1_attr":"sub1_attr_value" }]} } }"; [/java] And this JSON is same as… Read More »

Global variables in ANDROID……

By | May 17, 2011

Hi all……. In today’s exampl e I will show you how to deal with global variables in ANDROID. You know global variables are those variables that you can access across any variables. It’s value becomes changed when you change it in any of the classes in your project. These types of variables act as like cookies in a… Read More »

How to use Global variables in ANDROID?

By | May 17, 2011

Hi all……. In today’s exampl e I will show you how to deal with global variables in ANDROID. You know global variables are those variables that you can access across any variables. It’s value becomes changed when you change it in any of the classes in your project. These types of variables act as like cookies in a… Read More »

How to split a String in ANDROID?

By | May 5, 2011

Hi all….. Splitting a string in android is really easy.checkout the following snippet. [java] package com.coderzheaven; import android.app.Activity; import android.os.Bundle; public class SplitStringDemo extends Activity { String str = "India, USA, Japan, Russia, France"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String arr[] = str.split(","); for(int i = 0; i < arr.length; i++){ System.out.println("arr["+i+"] = " +… Read More »