Posts

Showing posts from 2011

Convert DateTime SQLite to GMT DateTime SQLite

static public String convertDateTimeToGMT(String in) { String out = in; SimpleDateFormat sdf = new SimpleDateFormat(Utility.getDBDateFormat()); Date iDate = null; try { iDate = sdf.parse(in); } catch (ParseException e) { Log.e(TAG, e.getMessage()); return in; } long newd = iDate.getTime() - sdf.getTimeZone().getRawOffset(); SimpleDateFormat osdf = new SimpleDateFormat(Utility.getDBDateFormat()); out = osdf.format(new Date(newd)); return out; }

Create JAR suitable for use with Dalvikvm

1. Create Helloworld.java: package org.apache; public class HelloWorld { public static void main(String[] args) { } } 2. Compile java: javac -d . -g Helloworld.java 3. Package Java Into a temporary jar jar -cvf Temp.jar * 4. Use DX to generate classes.dex from Temp.jar dx --dex --output=classes.dex Temp.jar 5. Use aapt to create new Jar (CmdLine.jar) suitable for use with Dalvikvm aapt add CmdLine.jar classes.dex 6. Push Jar to folder: adb shell     mount -o remount /system     exit adb push CmdLine.jar /system/framework/ 7. Restart: adb reboot

Create your own shared-library

Below is the step of creating own shared-library: Create JAVA file, ex: c:\com.myactivity.java Compress to JAR, with command: jar cf c:\com.myactivity.jar c:\com.myactivity.java JAR is our library file. Create XML file (permission file), ex: c:\com.myactivity.xml, as below: <permissions> <library name="com.myactivity" file="/system/framework/com.myactivity.jar" /> </permissions>  Root the OS image: adb root (We assume that the image can be rooted.) Mount /system, commands are as belows: adb shell mount –o remount /system exit  Push JAR and XML file to OS image: adb push c:\com.myactivity.jar /system/framework/ adb push c:\com.myactivity.xml /system/etc/permissions/  Reboot device. After rebooted, the shared-library can be used correctly. Try using to test the library. <uses-library android:name="com.myactivity" android:required="true" /> 

Shared Folder settings between Windows7 and uBuntu guest OS in VMWare

PS: Please make sure that your VMTools is installed correctly on the uBuntu Guest. http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1022525 Virtual Machine Settings Folder sharing = Always Enabled. Make sure you have at least one Folder shared between the host and guest. For example: my-D-drive On the uBuntu Guest check /mnt/hgfs that you can access your shared folder  If you cannot see the folder, then skip it. Next step will create the folder automatically. update your fstab using the details below: Open terminal and type: gksu gedit /etc/fstab Add below to the end of the file: .host:/{shared-folder} /{path-to-mount-on} vmhgfs defaults,ttl=5,uid=1000,gid=1000 0 0 Change {shared-folder} to the shared folder of Virtual Machine Settings (my-D-drive). Change {path-to-mount-on} to the folder inside uBuntu (/mnt/hgfs/my-D-drive). Restart your vm. You may need to restart few times or get error messa...

Connect localhost from VMWare Fusion using MAMP

I’m in the process of setting up a development environment on my mac. I’ve set up IE8 testing by converting Microsoft’s VPC images to a VMware compatible image . So the next thing I need to do is view my local webserver from VMware. Typing http://localhost doesn’t work because the virtual machine is an entity in itself so localhost is local to the virtual machine. Having done a little of this in the past I knew the hosts file in folder c:\windows\system32\drivers\etc would need an entry, mapping my Mac’s IP address to a domain name. Sean Sperte reveals a secret VMware IP address that is particularly handy when you use a laptop because a laptop’s IP address is not likely to remain static. I’ll quote Sean here: Type ifconfig vmnet1 into a Terminal window. You should get a return like this: vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet 192.168.115.1 netmask 0xffffff00 broadcast 192.168.115.255 ether 00:50:56:c0:00:01 The “inet” nu...

Using AssetManager on native language JNI, C++

#include <sstream> #include <assert.h> // include in android platform-9 or newer #include <android/asset_manager.h> #include <android/asset_manager_jni.h> ... JNIEXPORT void JNICALL Java_com_yourpackage_yourfunctionname(JNIEnv *env, jclass clazz, jobject assetManager) {     // get assetmanager native     AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);     assert(mgr != NULL);     // load file inside assets, "assets/a/b.txt"     AAsset* asset = AAssetManager_open(mgr, "a/b.txt", AASSET_MODE_UNKNOWN);     assert(asset != NULL);     // get buffer of file     char* buff = (char*) AAsset_getBuffer(asset);     assert(buff != NULL);     // print out buffer per line     const int MAX_BUF = 512;     char strbuf [MAX_BUF];     std::istringstream iss(buff);  ...

Things that always happen

Below could be happen when developing android app. Unable to open sync connection! Try to re-enable USB debugging on the phone. Forcely uninstall app. Find the apk file of app. Remove the apk file: adb shell rm /system/sd/app/com.android.cardock.apk PS: needs ROOT. ... continue

Installing LAMP On Ubuntu For Newbies

In this guide I will show you how to install a LAMP system. LAMP stands for L inux, A pache, M ySQL, P HP. The guide is intended to help those who have very little knowlegde of using Linux. Install Apache To start off we will install Apache. 1. Open up the Terminal ( Applications > Accessories > Terminal ). 2. Copy/Paste the following line of code into Terminal and then press enter: sudo apt-get install apache2 3. The Terminal will then ask you for you're password, type it and then press enter. Testing Apache To make sure everything installed correctly we will now test Apache to ensure it is working properly. 1. Open up any web browser and then enter the following into the web address: http://localhost/ You should see a folder entitled apache2-default/ . Open it and you will see a message saying "It works!" , congrats to you! Install PHP In this part we will install PHP 5. Step 1. Again open up the Terminal ( Applications > Accessories >...

ADB shell upload fail

Try to: Install correct driver. Setting USB Device to DEBUG mode. And last (what I got), REMOVE ALL USB HUB.. WHY? It is because adb conflicts with USB HUB, because adb is using socket to communicate between OS and device. Hope this can help. :)