Displaying keyword search results 131 - 140
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:
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 Dr. Xi on April 17, 2011 21:34:20 Last update: April 17, 2011 21:34:20
#!/usr/bin/python # -*- coding: latin-1 -*- ...
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 freyo on April 12, 2011 13:05:33 Last update: April 12, 2011 13:06:26
android:sharedUserId (from Android doc): The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process. Declare sharedUserId in AndroidManifest.xml :
<manifest xmlns:android="http://schemas.android.co...Retrieve sharedUserId programmatically:
import android.content.pm.PackageManager; impor...
Created by alfa on April 08, 2011 14:14:46 Last update: April 08, 2011 14:26:13
It's a lot easier to use swing JOptionPane to present a dialog. But if plain awt is what you want, this is the code. A Dialog is a Window object, so you paint it just like you would for a window.
import java.awt.*; import java.awt.event.*; ...
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 04, 2011 18:09:43 Last update: April 08, 2011 12:27:11
import java.awt.Graphics; import java.awt.event...
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...