Recent Notes

Displaying keyword search results 111 - 120
Created by freyo on May 23, 2011 14:30:18    Last update: May 23, 2011 14:31:08
There are two distinct ways to process XPath: with namespace and without namespace. The code is different depending on whether the parser is namespace aware. Code without namespace: import java.io.*; import javax.xml.parsers.*; ... code with namespace: import java.io.*; import java.util.Iterator; ... XML without namespace: <?xml version="1.0" encoding="UTF-8" standalone="n... XML with namespace: <?xml version="1.0" encoding="UTF-8" standalone="n... The same XPath expression works for both XML files when the parser is not namespace aware. When the parser is namespace aware, you have to adjust the XPath accordingly depending on whether the XML has namespace declarations: " /test-license/licensee/name/text() " works for the XML file without namespace, while " /p:test-license/p:licensee/p:name/text() " works for the XML file with namespace.
Created by freyo on May 20, 2011 09:25:20    Last update: May 23, 2011 12:11:42
The javax.xml.crypto and javax.xml.crypto.dsig packages are not available in Android (as of version 2.3). Therefore, standard Java API does not work. But you can use the Apache Santuario library to do that. Here are the steps: Download the xml security source distribution (curently version 1.4.4). Build with ant. Create your own library jar (only the apache classes, no javax): jar -cf xmlsec-1.4.4.jar -C build/classes org Copy xmlsec-1.4.4.jar to the libs directory of your Android project. Here's the Java code: import java.io.*; import javax.xml.parsers.*; ...
Created by freyo on May 23, 2011 12:07:59    Last update: May 23, 2011 12:09:42
You can construct a java.security.cert.Certificate object from a string or byte array. Byte array is cleaner because for string you also have to know the character encoding. // import java.security.cert.CertificateFactory; ... If the certificate string is encoded in "UTF-8", the ByteArrayInputStream should be created with: new ByteArrayInputStream(certString.getBytes("UTF-...
Created by Dr. Xi on May 17, 2011 21:14:58    Last update: May 17, 2011 21:17:58
Read certificate one at a time from BufferedInputStream : // import java.security.cert.*; public void rea... Read all certificates from a file as a collection: public void readCertificates(File f) throws Except...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by freyo on May 09, 2011 15:13:59    Last update: May 09, 2011 15:14:22
This code snippet opens and reads the Android APK archive file for a given package name. // import java.io.*; // import java.util.zip.*;...
Created by freyo on May 09, 2011 14:52:13    Last update: May 09, 2011 14:52:13
From string user id to int uid: // import android.os.Process; int uid = Process... From int uid to string user id: // import android.content.pm.PackageManager; Pa...
Created by freyo on April 12, 2011 13:30:33    Last update: May 09, 2011 14:43:46
You can look at the file /data/system/packages.xml to find out which package is using a particular sharedUserId . Copy the file /data/system/packages.xml to the local drive with: adb pull /data/system/packages.xml packages.xml Open the file in an editor, search for the shared user id, for example: com.google.android.apps.maps Search for packages with the corresponding numerical id of sharedUserId , for example: sharedUserId="10017" Or, Programatically : // import android.os.Process; PackageInfo pkgIn...
Created by freyo on May 09, 2011 14:15:01    Last update: May 09, 2011 14:17:22
In short, use the PackageManager class to get the PackageInfo : PackageInfo pkgInfo = getPackageManager().getP... To build an APK, make these changes to the greetings app : Change the layout to ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Change the string values ( res/values/strings.xml ): <?xml version="1.0" encoding="utf-8"?> <resourc... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new Java class src/com/android/appinfo/GetAppVersion.java : package com.android.appinfo; import android... Edit build.xml , change project name to "AppInfo": <?xml version="1.0" encoding="UTF-8"?> <project... Install to emulator: ant install Screenshot:
Created by freyo on May 09, 2011 12:50:52    Last update: May 09, 2011 12:51:54
You can use the android.os.StatFs class to check for available space on the sd card. Example code: // import android.os.Environment; // import...
Previous  7 8 9 10 11 12 13 14 15 16 Next