Recent Notes
Displaying keyword search results 41 - 50
Created by freyo on April 18, 2011 15:08:21
Last update: April 18, 2011 15:12:20
Generate android project
$ ~/android-sdk-linux_86/tools/android create proj...
Create XML file res/xml/books.xml :
<?xml version="1.0"?>
<catalog>
<book id=...
Edit layout ( res/layout/main.xml ):
<?xml version="1.0" encoding="utf-8"?>
<Lin...
Edit code ( src/com/android/xmlres/XMLResource.java ):
package com.android.xmlres;
import java.io....
Change activity label from app_name to booklist ( AndroidManifest.xml ):
<?xml version="1.0" encoding="utf-8"?>
<manifes...
Add value for string resource ( res/values/string.xml ):
<?xml version="1.0" encoding="utf-8"?>
<resourc...
Deploy and test:
ant install
Created by freyo on April 18, 2011 14:14:29
Last update: April 18, 2011 14:15:48
For XML resources, Android returns an XmlPullParser reference. I tried the RSSReader example from xmlpull.org , it failed both on the Android emulator and with xpp3-1.1.4c .
This is an example for XmlPullParser usage. Since the XmlPullParser is event based, a callback mechanism works better.
Java code:
import java.io.*;
import java.net.*;
import ...
The XML file used:
<?xml version="1.0" encoding="UTF-8"?>
<catalog...
Created by freyo on April 15, 2011 09:00:54
Last update: April 15, 2011 09:00:54
Sample code for writing to a file in the internal storage. There are three steps:
Open the file with Context.openFileOutput , which returns java.io.FileOutputStream .
Write to the file.
Close the file.
import java.io.*;
import android.content.Contex...
The second parameter to openFileOutput is the operating mode. Available values are:
Context.MODE_PRIVATE
Context.MODE_APPEND
Context.MODE_WORLD_READABLE
Context.MODE_WORLD_WRITEABLE
The file is saved in /data/data/<package_name>/files .
Created by alfa on April 08, 2011 12:33:08
Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen.
import java.io.*;
import java.awt.*;
import ...
Created by alfa on April 08, 2011 11:05:24
Last update: April 08, 2011 11:05:24
Key points:
Use java.awt.Robot to capture a screen region as java.awt.image.BufferedImage .
Use javax.imageio.ImageIO to write image out to a file.
import java.awt.AWTException;
import java.awt.R...
Created by nogeek on April 07, 2011 21:30:54
Last update: April 07, 2011 21:30:54
This is the opposite of parsing. You can use javax.xml.transform.Transformer to output a DOM tree to a file.
import java.io.*;
import javax.xml.parsers.Docu...
Created by nogeek on April 07, 2011 20:54:17
Last update: April 07, 2011 20:54:17
Use javax.xml.parsers.DocumentBuilder to parse xml. DocumentBuilder.parse() takes:
java.io.File
org.xml.sax.InputSource
java.io.InputStream
java.lang.String as a URI to an XML document
Example code:
import java.io.*;
import javax.xml.parsers.Docu...
Created by freyo on April 07, 2011 15:29:01
Last update: April 07, 2011 15:29:01
Format Name Description PKCS #7 Cryptographic Message Syntax Standard A PKCS #7 file can be used to store certificates, which is a SignedData structure without data (just the certificates). The file name extension is usually .p7b , .p7c PKCS #8 Private-Key Information Syntax Standard. Used to carry private certificate keypairs (encrypted or unencrypted). PKCS #12 Personal Information Exchange Syntax Standard. Defines a file format commonly used to store private keys with accompanying public key certificates, protected with a password-based symmetric key. It is the successor to PFX from Microsoft. DER Distinguished Encoding Rules A binary format for keys or certificates. It is a message transfer syntax specified by the ITU in X.690. PEM Privacy Enhanced Mail Base64 encoded DER certificates or keys, with additional header...
Created by alfa on April 06, 2011 13:23:40
Last update: April 06, 2011 13:23:40
A file can be read as URL with the java.net package. You must provide absolute path after the URI scheme name file:// .
package com.demo.io;
import java.io.*;
i...
Created by alfa on April 06, 2011 12:48:44
Last update: April 06, 2011 12:48:44
package com.demo.io;
import java.io.*;
...