Displaying keyword search results 131 - 140
Created by Dr. Xi on April 26, 2011 21:25:55 Last update: April 27, 2011 11:08:57
The following code validates a web.xml file against the web-app 2.5 schema:
// Java XML validation with schema import java....web.xml used for testing:
<?xml version="1.0" encoding="UTF-8"?> <web-ap...According to Java API doc , validation can also be done while parsing by calling setSchema on the parsing factory. However, validation doesn't work for the SAXParserFactory!
// Java XML validation with schema import java....
Created by freyo on April 21, 2011 11:41:42 Last update: April 21, 2011 11:41:42
How to enable wifi with Java code:
import android.net.wifi.WifiManager; . . ...
Created by freyo on April 20, 2011 12:26:08 Last update: April 20, 2011 12:26:08
When you create a new key with Java keytool , it wraps the public key in a self signed certificate. You can generate a certificate signing request with the keytool -certreq command. After a certificate authority (CA) signs the certificate request, you can import the certificate received (a .crt file) back into the key store. Instead of using a CA, you can sign the certificate request with another key (with openssl, for example). If the certificate is not signed by a CA, you'll receive an error:
$ keytool -import -alias android-root -file androi...To fix the problem, import the certificate of the signer:
$ keytool -import -trustcacerts -file openssl.crt ...Import the certificate again (alias is the alias of the private key whose certificate was...
Created by jk34 on April 19, 2011 15:42:24 Last update: April 19, 2011 15:42:24
Check the __name__ variable to see if the Python module was invoked from the command line. The line prints when the Python script is called from the command line, but doesn't print when it is imported by another Python module with import MyModule .
if __name__ == '__main__': print 'Invoked f...
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.*; ...