Friday, October 15, 2010

[Android Snippet] Adler32 in Android

Minimum API Level : 1
Key class: Adler32

Adler32 is one of checksum algorithms. Compared with other algorithms, Adler32 provides reliability for speed.
This snippet showing how to calculate Adler32 value in Android application


public long calculateAdler32(byte[] data){
Adler32 adler = new Adler32();
adler.update(data);
return adler.getValue();
}

Thursday, October 7, 2010

[Android Snippet] CRC32 in Android

Minimum API Level : 1

Key class: CRC32

CRC (Cyclic Redundancy Check) is one of checksum algorithms that designed for digital data verification purpose. This snippet is showing how to calculate CRC32 value from byte array data using CRC32 class



public long calculateCrc32(byte[] data){
CRC32 crc = new CRC32();
crc.update(data);
return crc.getValue();
}

[Android Snippet] GZip Compression

Minimum API Level : 1

key class : GZipOutputStream , GZipInputStream

This snippet showing how to compressing file using GZipOuputStream and decompressing using GZipInputStream.

Compress


Log.v(TAG, "Start Compress");
FileInputStream fIn = new FileInputStream(INPUT_PATH);
FileOutputStream fOut = new FileOutputStream(OUTPUT_PATH);
GZIPOutputStream gZip = new GZIPOutputStream(fOut);
byte[] buf = new byte[BUFFER_SIZE];

int readCount = fIn.read(buf);
while(readCount > 0){
gZip.write(buf, 0, readCount);
readCount = fIn.read(buf);
}
gZip.finish();
gZip.close();
fIn.close();
Log.v(TAG, "Compress Success");


Decompress


Log.v(TAG, "Start Decompress");
FileInputStream fIn = new FileInputStream(INPUT_PATH);
FileOutputStream fOut = new FileOutputStream(OUTPUT_PATH);
GZIPInputStream gZip = new GZIPInputStream(fIn);
byte[] buf = new byte[BUFFER_SIZE];

int decompressCount = gZip.read(buf, 0, BUFFER_SIZE);
while(decompressCount > 0){
fOut.write(buf, 0, decompressCount);
decompressCount = gZip.read(buf, 0, BUFFER_SIZE);
}
gZip.close();
fOut.close();
Log.v(TAG, "Decompress Success");

[Android Snippet] How to retrieve running process

Minimum API Level : 3

Key Class : ActivityManager , ActivityManager.RunningAppProcessInfo

Here is my Android code snippet showing how to retrieve information about application processes that are running on the device



ActivityManager manager = (ActivityManager)
getSystemService(Activity.ACTIVITY_SERVICE);
List list = manager.getRunningAppProcesses();
Log.v(TAG, "Got "+list.size()+" processes");

for(int i=0; i<list.size(); i++){
Log.v(TAG, "PID: "+list.get(i).pid+", Name: "+list.get(i).processName);
}

Move Forward !

I have moved my blog entries from WordPress to Blogspot since it usually have SSL problem when I signed in to my wordpress account