Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Thursday, April 5, 2012

Android Big Phone screen not filled up

When I put the code that ran for my Android Nexus S on the bigger Android Galaxy Note phones, the screen was not filled up completely, maybe just the top 70%. What I did to fix this was add in this line into the Manifest:

<uses-sdk android:minSdkVersion="4" />

4 or higher works. If you don't have this line, it's assumed to be 1 by default.

Tuesday, January 17, 2012

Android TCP and UDP basic code examples

This is a tiny app that has examples for both android TCP and UDP communications.

Remember, you should:

TCP - start the server first, because ServerSocket.accept() blocks

UDP - start the client first, because DatagramSocket.receive() blocks 

Sunday, May 1, 2011

Synchronize Android Phone with Eclipse app development

Trying on 6857_proj with Android 1.6, because my APG is for Android 2.2, but my phone has version 1.6.

Following Setting up a Device for Developement

I have a T-Mobile, which I couldn't find on the list of "USB Vendor IDs", so I used the lsusb to see that I have a "Bus 002 Device 003: ID 0bb4:0c02 High Tech Computer Corp. Dream / ADP1 / G1 Phone (Debug)". So for T-Mobile, it's the same as HTC: SYSFS{idVendor}=="0bb4". (I didn't know T-Mobile is related to HTC)

android-sdk-linux_x86/platform-tools$ ./adb devices
List of devices attached
HT93LLZ01057 device

Then I clicked on "Run" and saw in the counsole:
[2011-05-01 16:30:05 - Apg] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.thialfihar.android.apg/.MainActivity }
[2011-05-01 16:30:20 - 6857_proj] Success!
[2011-05-01 16:30:20 - 6857_proj] Starting activity org.thialfihar.android.apg.MainActivity on device HT93LLZ01057
[2011-05-01 16:30:23 - 6857_proj] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.thialfihar.android.apg/.MainActivity }


Yay! I saw APG on my Phone! :D

========
get ZXing to work:

Pretty easy actually. Just press "Run" and everything is figured out automatically.  Even though my project is for Android 2.3.1 and my phone is 1.6, things worked out! I didn't change anything to the project code! Did NOT add '<application android:debuggable="true" ' in AndroidManifest.xml.

Console message:
[2011-05-02 01:13:07 - Zxing2] ------------------------------
[2011-05-02 01:13:07 - Zxing2] Android Launch!
[2011-05-02 01:13:07 - Zxing2] adb is running normally.
[2011-05-02 01:13:07 - Zxing2] Performing com.google.zxing.client.android.CaptureActivity activity launch
[2011-05-02 01:13:07 - Zxing2] Automatic Target Mode: using device 'HT93LLZ01057'
[2011-05-02 01:13:07 - Zxing2] Uploading Zxing2.apk onto device 'HT93LLZ01057'
[2011-05-02 01:13:08 - Zxing2] Installing Zxing2.apk...
[2011-05-02 01:13:14 - Zxing2] Success!
[2011-05-02 01:13:15 - Zxing2] Starting activity com.google.zxing.client.android.CaptureActivity on device HT93LLZ01057
[2011-05-02 01:13:18 - Zxing2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.zxing.client.android/.CaptureActivity }
I did NOT even do the "Run on Android" part of http://code.google.com/p/zxing/wiki/GettingStarted.



Failed attempts at ZXing, I was being too cautious and hit some deadends
I think I should start a new ZXing that is compatible with my 1.6 phone.

If I choose version 1.6, I'll have 2 problems:
1. "R cannot be resolved" because gen > > R.java is not created from Project > clean
2. AndroidManifest.xml gives a "error: No resource identifier found for attribute 'installLocation' in package 'android'" of this line: <manifest xmlns:android="http://schemas.android.com/apk/res/android"

Both of these problems can be resolved if I upgrade the version to 2.3.1 by right clicking on the project name "Properties" and choose 2.3.1.

Might be helpful:
http://stackoverflow.com/questions/4782543/solved-integration-zxing-library-directly-into-my-android-application
"Run on Android" of http://code.google.com/p/zxing/wiki/GettingStarted ... I never had to do it.

Sunday, April 24, 2011

Adding SD Card to Android Emulator in Eclipse

1. Navigate to your android-sdk directory's "tools", for example, your equivalent of "android-sdk-linux_x86/tools"
2. Do ./mksdcard 64M YourSdCardName
3a. Run the emulator in Eclipse, do, or if you have Windows, follow this

  1. Run > Run Configurations
  2. Select the "Target" Tab
  3. Scroll down to "Additional Emulator Command Line Options" and add in
  4. -sdcard [Your full path to ]/tools/YourSdCardName
  5. Apply
  6. Run

3b. Run the emulator in the terminal:
        ./emulator -avd YourAndroidEmulatorName -sdcard YourSdCardName

Saturday, April 23, 2011

Resizing Android Emulator in Eclipse

If the size of the emulator is too big. You can resize it by:
1. Run > Run Configurations
2. Pick the "Target" tab
3. Scroll down to Additional Emulator Command Line Options and put in: "-scale 0.8" or another number

ZXing

How I set up ZXing
  1. download ZXing file
  2. Follow the directions in here under "Run" stop at "Run on Android".
      A test [URL] can be, in .../zxing-read-only, $ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner http://www.idautomation.com/ucc_ean_128.jpeg
      http://www.idautomation.com/ucc_ean_128.jpeg (format: CODE_128, type: TEXT): Raw result: 81007123452112345678 Parsed result: 81007123452112345678 Also, there were 2 result points. Point 0: (12.5,26.0) Point 1: (167.5,26.0)
  3. You should set up a new Android project by doing: File > New > Project > Select "Android Project" under Android > Next > Create project from existing source and navigate to the "android" folder of your downloaded ZXing file. Put a name. and a platform.
  4. At this point, I got errors like this:
    The import com.google.zxing.BarcodeFormat cannot be resolved (at least in src > com.google.zxing.client.android > CaptureActivity.java)
    Here is the way to fix these errors, adapted from here.
    Right click on Project Name
    - Go to New -> Source Folder
    - For Folder name, call it "srccore"
    - Click on Finish

    Right click on "srccore"
    - Click on Import
    - Click on File System > Next
    - For "From directory:" type in [full path to]/zxing/core/src
    - Make sure the checkbox next to "src" is checked
    - Finish

    Go to Project -> Clean
  5. Run it (might take a while), you should see the square moves around:


  6. Done! Btw, if you want to resize your emulator.
I don't have a real phone, should look at this to fake a camera.

Old notes with things that didn't work
haoqili@stay-focused-hq:13:04:51:~/Desktop/6.857/proj/zxing-read-only$ cd core
haoqili@stay-focused-hq:13:04:52:~/Desktop/6.857/proj/zxing-read-only/core$ ant
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:

build:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build

BUILD FAILED
/home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml:54: The following error occurred while executing this line:
/home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml:37: Error running javac compiler

Total time: 1 second

http://ubuntuforums.org/archive/index.php/t-870670.html


haoqili@stay-focused-hq:13:12:51:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-alternatives --config java
[sudo] password for haoqili:
There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java
Nothing to configure.


http://www.webupd8.org/2010/10/sun-java-finally-uploaded-to-ubuntu.html

sudo apt-get update

sudo apt-get install sun-java6-jre

sudo apt-get install sun-java6-jdk




haoqili@stay-focused-hq:15:57:05:/usr/lib/jvm$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).


  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode


Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

haoqili@stay-focused-hq:15:23:34:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-java-alternatives -l
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
haoqili@stay-focused-hq:15:25:49:~/Desktop/6.857/proj/zxing-read-only/core$ sudo update-java-alternatives -l
[sudo] password for haoqili: 
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
haoqili@stay-focused-hq:15:58:54:~/Desktop/6.857/proj/zxing-read-only/core$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:
   [delete] Deleting directory /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build

build:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

BUILD SUCCESSFUL
Total time: 8 seconds
haoqili@stay-focused-hq:15:59:20:~/Desktop/6.857/proj/zxing-read-only/core$ cd ../javase
haoqili@stay-focused-hq:16:03:32:~/Desktop/6.857/proj/zxing-read-only/javase$ ls
build.xml  pom.xml  src
haoqili@stay-focused-hq:16:03:33:~/Desktop/6.857/proj/zxing-read-only/javase$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build.xml

init:

build:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build
    [javac] Compiling 6 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/javase/javase.jar

BUILD SUCCESSFUL
Total time: 6 seconds
haoqili@stay-focused-hq:16:03:44:~/Desktop/6.857/proj/zxing-read-only/javase$ 



haoqili@stay-focused-hq:16:04:27:~/Desktop/6.857/proj/zxing-read-only$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner [URL]
Exception in thread "main" java.net.URISyntaxException: Illegal character in path at index 0: [URL]
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3066)
at java.net.URI$Parser.parse(URI.java:3024)
at java.net.URI.<init>(URI.java:578)
at com.google.zxing.client.j2se.CommandLineRunner.decodeOneArgument(CommandLineRunner.java:210)
at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:104)

haoqili@stay-focused-hq:16:04:49:~/Desktop/6.857/proj/zxing-read-only$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner http://www.idautomation.com/ucc_ean_128.jpeg
http://www.idautomation.com/ucc_ean_128.jpeg (format: CODE_128, type: TEXT):
Raw result:
81007123452112345678
Parsed result:
81007123452112345678
Also, there were 2 result points.
  Point 0: (12.5,26.0)
  Point 1: (167.5,26.0)



===========
Android



[2011-04-23 16:45:51 - ZXing] ERROR: Unable to open class file /home/haoqili/workspace/ZXing/gen/com/google/zxing/client/android/R.java: No such file or directory

Then I run emulator, when I click on the scan barcode ap, goes black blank and goes to front page again.

===
Second (Android) part of: 
http://code.google.com/p/zxing/wiki/GettingStarted

android-home=/home/haoqili/Desktop/6.857/proj/android-sdk-linux_x86
proguard-jar=/home/haoqili/Desktop/6.857/proj/proguard4.6/lib/proguard.jar


haoqili@stay-focused-hq:17:39:53:~/Desktop/6.857/proj/zxing-read-only/core$ ant clean build-no-debug
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build.xml

clean:
   [delete] Deleting directory /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
   [delete] Deleting: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

clean:

build-no-debug:

init:

compile:
    [mkdir] Created dir: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
    [javac] Compiling 177 source files to /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/build
      [jar] Building jar: /home/haoqili/Desktop/6.857/proj/zxing-read-only/core/core.jar

BUILD SUCCESSFUL
Total time: 6 seconds


I copied the contents of android to workspace/ZXing, so I went there to "build android"

haoqili@stay-focused-hq:17:41:28:~/workspace/ZXing$ ant
Buildfile: /home/haoqili/workspace/ZXing/build.xml

BUILD FAILED
/home/haoqili/workspace/ZXing/build.xml:64: taskdef class com.android.ant.SetupTask cannot be found
 using the classloader AntClassLoader[]

Total time: 0 seconds

===
Looks like I shouldn't have moved it. 
Eck. Try again by building a project from the file (see top)

The scanner worked [insert pictures]

==
last step of Building android is stil bad

haoqili@stay-focused-hq:22:11:37:~/Desktop/6.857/proj/zxing-read-only/android$ ant
Buildfile: /home/haoqili/Desktop/6.857/proj/zxing-read-only/android/build.xml

BUILD FAILED
/home/haoqili/Desktop/6.857/proj/zxing-read-only/android/build.xml:64: taskdef class com.android.ant.SetupTask cannot be found
 using the classloader AntClassLoader[]

Total time: 0 seconds


Wednesday, April 13, 2011

Setting up Android Privacy Guard + Bouncy Castle from scratch

The APG project suggested using the Bouncy Castle to as a way to learn how to building the APG. Here are some very detailed steps on how to do this from complete scratch, as if it's your first Android project.

The order of getting things working will be:
I. Set up Eclipse with Android Development SDK and ADT emulator
II. Create a new Android Project with APG and Bouncy Castle incoporated in

I. Setting up Android Development on Eclipse, roughly following the Android SDK Installation Guide.
  1. Download Eclipse Classic. (Windows: if it asks, install Java SDK)
  2. Download the Android SDK. (Windows: if it says Java SDK not found when you have installed it, hit "Back" and "Next" :/ ... good job Windows)
  3. Get the Eclipse ADT Plugin for Android Emulator in Eclipse by doing:
    Select Help > Install New Software. Add at top right, Name: "ADT Plugin", Location: "https://dl-ssl.google.com/android/eclipse/", or "http: ..". Okay. Next. Next. Accept. Finish. Restart Now.
  4. Check that this exists: "Window > Android SDK and AVD Manager" If you get this error: "Location of the Android SDK has not been setup in the preferences". You need to do: a) Window > Preferences > Android b) Put in appropriate path file for the "android-sdk-[OS name]" directory in SDK Location, which should come from your "Android SDK" download (If you downloaded the .exe for Windows, download the zip) c) Apply. OK
  5. Install Android Packages on ADT:
    Click on "Window > Android SDK and AVD Manager"
    Click on "Available packages" on the left.
    Check the "Android Repository".
    Press "Install Selected" and "Install"
II. Creating our own Android Virtual Device (AVD) with the APG Project and Bouncy Castle installed on it, roughly following the Android Creating AVDs Guide.
  1. If you don't have SVN, install it. (For Windows, download TortoiseSVN will require restart)
  2. SVN checkout the APG source code. (If you're using TortoiseSVN. Create a folder named "android-privacy-guard-read-only", right click on it, click on "SVN Checkout", and paste the url in.)
  3. Download the Bouncy Castle source code, which should extract to "bc145_reduced_for_apg" folder
  4. Create a new Android project on Eclipse:
    - File > New > Project
    - Click on Android > Android Project. Next. Fill in the rest as the picture shows:
  5. Replace with the APG source code: Navigate to workspace/Apg and replace everything inside there with the files in the Apg source you downloaded in the previous step (so replace src, res, AndroidManifest.xml, etc). 
  6. Add the Bouncy Castle code: copy the bouncycastle2 directory (inside bc145_reduced_for_apg/org) into workspace/Apg/src/org
  7. Run > run: (warning, it'll take a while, a black blank screen doesn't mean it's broken). You should see something like:
  8. Extra: If the size of the emulator is too big. You can resize it by:
    Run > Run Configurations > Target [a tab]
    Write in Additional Emulator Command Line Options: "-scale 0.8" or another number
  9. DONE!

Useless stuff: the long way of doing #4 onwards
  1. Create a new Android project on Eclipse:
    - File > New > Project
    - Click on Android > Android Project. Next.
    - Project name: "6857proj". Target Name: "Android 1.6". Package Name: "org.thialfihar.android.apg". Create Activity: "proj6857". Finish.
  2. Make a new AVD for this project:
    - select "6857proj" form the "Package Explorer" on the left side.
    - Run > Run
    - "Yes" to "No compatible targets were found. Do you wish to add a new AVD?"
    - "New" on top right
    - Name: "6857avd" Target: "Android 1.6". Create AVD
    - Select on the "6857avd" and click "Start". "Launch".
    - Wait for 3+ minutes for the Android emulator to turn on
  3. Add the APG source code into our Android Project:
    - copy all the files and folders inside "android-privacy-guard-read-only -> src -> org -> thialfihar -> android -> apg" into to "[your Eclipse] workspace -> 6857proj -> src -> org -> thialfihar -> android -> apg"
  4. Add the Bouncy Castle code into our Android Project:
    - copy this directory "bc145_reduced_for_apg -> org -> bouncycastle2" into "[your Eclipse] workspace -> 6857proj -> src -> org". So you should end up with "thialfihar" and "bouncycastle2" in the "org" directory.
  5. Put the APG resources into the res of the Android Project:
    - delete the "res" directory in the workspace, and replace it with APG's "res"
  6. Run > run: (warning, it'll take a while, a black blank screen doesn't mean it's broken)
    If you can't run due to errors like "The method xx of type xx must override a superclass", do:
    - Project > Properties
    - Under "Java Compiler," change the compiler compliance level from "1.5" to "1.6". Apply.
    - Now you should be able to run.
  7. Done!
  8. To fix this warning below, you have to replace the "AndroidManifest.xml" with the Apg's version too.
    Sorry!
    The application APG (process org.thialfihar.android.apg) has stopped unexpectedly.
    Please try again.

  9. Extra: If the size of the emulator is too big. You can resize it by:
    Run > Run Configurations > Target [a tab]
    Write in Additional Emulator Command Line Options: "-scale 0.8" or another number

I tried debugging that "stopped unexpectedly" error for a long time. Here are the things I learned:

Finding the base java file: I tried to match up with  the tutorial by grepping for "extends Activity". I found it in the org/thialfihar.android.apg/BaseActivity.java file, which also has onCreate().

Debugger can be useless: I tried placing a break in the first line of the main function in the basefile. When I ran Run > Debug History and started stepping through the files, a lot of Source not found came up. It was misleading, because when I tried breaking in similar fashions in a working "Hello Android" project, the same "Source not found" errors came up.

LogCat is supposed to help debugging, but since I had no idea what the code was about, it wasn't helpful for me.

Android 6.857 Project Start

We would like to use QR codes to build a web-of-trust for smart phone users.  (Final project for 6.857)

We decided to base off our code with the APG project, which source code can be found here.  The APG project suggested using the Bouncy Castle to learn building APG. The details can be found here.

Friday, April 8, 2011

Setting Up Android Development

Check that adb works:
haoqili@stay-focused-hq:~/Desktop/6.857/proj/android-sdk-linux_x86/platform-tools$ ./adb shell
# id
uid=0(root) gid=0(root)
# exit


Integrate APG (by its .apk) into Android SDK:

haoqili@stay-focused-hq:~/Desktop/6.857/proj/android-sdk-linux_x86/platform-tools$ ./adb install /home/haoqili/Desktop/6.857/proj/APG-1.0.8-release.apk
1678 KB/s (1089338 bytes in 0.633s)
pkg: /data/local/tmp/APG-1.0.8-release.apk
Success


Go to simulator phone. It's there in the panels!