Sunday, December 4, 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;
}

Thursday, November 3, 2011

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

Wednesday, October 5, 2011

Create your own shared-library

Below is the step of creating own shared-library:

  1. Create JAVA file, ex: c:\com.myactivity.java
  2. Compress to JAR, with command: jar cf c:\com.myactivity.jar c:\com.myactivity.java
    • JAR is our library file.
  3. Create XML file (permission file), ex: c:\com.myactivity.xml, as below:
    <permissions>
    <library name="com.myactivity" file="/system/framework/com.myactivity.jar" />
    </permissions> 
  4. Root the OS image: adb root (We assume that the image can be rooted.)
  5. Mount /system, commands are as belows:
    adb shell
    mount –o remount /system
    exit 
  6. 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/ 
  7. Reboot device.
  8. After rebooted, the shared-library can be used correctly.
  9. Try using to test the library.
    <uses-library android:name="com.myactivity" android:required="true" /> 

Wednesday, September 21, 2011

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 message saying unable to mount just skip the error and restart.
Reference: http://askubuntu.com/questions/29284/how-do-i-mount-shared-folders-win7-host-in-ubuntu-guest-using-vmwaretools-v6

    Tuesday, September 20, 2011

    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” number is your “secret” IP (in my case, 192.168.115.1).
    Now that we have that number, we can edit the hosts file on the VM. We find it in: C:/WINDOWS/system32/drivers/etc. Just open the host file with Notepad, and add each virtual host (domain) on it’s own line at the end of the document, like so:

    192.168.115.1 macserver

    … and save. Afterwards refresh the VM’s DNS cache by typing ipconfig /flushdns in a command line window.
    This worked perfectly for me.
    Reference: http://www.rowlando.com/blog/2009/01/11/reaching-localhost-from-vmware-virtual-machines-on-a-mac/

    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);
        while ( iss.getline(strbuf, MAX_BUF) )
            LOGE("%s", strbuf);

        AAsset_close(asset);
    }

    Tuesday, April 12, 2011

    Things that always happen

      Below could be happen when developing android app.
      1. Unable to open sync connection!
        • Try to re-enable USB debugging on the phone.
      2. 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.
      3. ... continue

        Friday, April 8, 2011

        Installing LAMP On Ubuntu For Newbies

        In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. 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 > Terminal).
        Step 2. Copy/Paste the following line into Terminal and press enter:
        sudo apt-get install php5 libapache2-mod-php5
        Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:
        sudo /etc/init.d/apache2 restart

        Test PHP

        To ensure there are no issues with PHP let's give it a quick test run.
        Step 1. In the terminal copy/paste the following line:
        sudo gedit /var/www/testphp.php
        This will open up a file called phptest.php.
        Step 2. Copy/Paste this line into the phptest file:
        <?php phpinfo(); ?>
        Step 3. Save and close the file.
        Step 4. Now open you're web browser and type the following into the web address:
        http://localhost/phptest.php
        Congrats you have now installed both Apache and PHP!

        Install MySQL

        To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)
        Step 1. Once again open up the amazing Terminal and then copy/paste this line:
        sudo apt-get install mysql-server
        Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.
        gksudo gedit /etc/mysql/my.cnf
        Change the line
        bind-address = 127.0.0.1
        And change the 127.0.0.1 to your IP address.
        Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal:
        mysql -u root
        Following that copy/paste this line:
        mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
        (Make sure to change yourpassword to a password of your choice.)
        Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:
        sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
        After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
        gksudo gedit /etc/php5/apache2/php.ini
        Now we are going to have to uncomment the following line by taking out the semicolon (;).
        Change this line:
        ;extension=mysql.so
        To look like this:
        extension=mysql.so
        Now just restart Apache and you are all set!
        sudo /etc/init.d/apache2 restart

        The End

        Quick note to anyone who encountered problems with setting up the MySQL password, please refer to this page: MysqlPasswordReset
        I applaud everyone who has taken the time to read this guide. This guide is also my first ever so I would love to hear back from the public on what you guys think! Just don't be too harsh. ;)
        If you have questions about installing any part of LAMP just drop them in the comment box and I will do my best to help you out.
        Source: http://www.howtoforge.com/ubuntu_lamp_for_newbies

        Wednesday, March 30, 2011

        ADB shell upload fail

        Try to:
        1. Install correct driver.
        2. Setting USB Device to DEBUG mode.
        3. 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. :)

        [ROM] Samsung S7 Stock Firmware BRI (Taiwan台灣)

        Latest ROM: G930FXXU1DQEU Download: https://kfhost.net/tpl/firmwares.php?record=B7E6DE774E3811E7963AFA163EE8F90B Reference: http://...