Android

SSHDroid, AirDroid

As Google decided to remove USB mass storage support from recent android-versions (starting with version 4.0 - "Ice Cream sandwich") the phone can only be connected via PTP or MTP support. AFAIK this works quite well with Windows and Mac but unfortunately not very well with Linux.
There are however other methods to connect the phone. Two of them I used are:

Both can be obtained from the Google App Store.
SSHDroid sets up an SSH-Server on the Android phone. File transfer can be done via every ssh-able client (command line, explorer, nautilus...).
AirDroid is far more advanced. It sets up a Web server on the Android phone and lets you connect via a standard Web browser to the Android phone. Besides transfer of video, audio or picture files it allows access to standard moblie phone functionalities, like SMS writing (or reading) or camera.
For detailed descriptions of how to set up the tools please refer to the links.

Taggings:

Create android application with phonegap using HTML5, CSS3, JavaScript

PhoneGap allows you to use standard web technologies such as HTML5, CSS3, and JavaScript for cross-platform development, avoiding each mobile platforms' native development language. Applications execute within wrappers targeted to each platform, and rely on standards-compliant API bindings to access each device's sensors, data, and network status.
Since the front end of the application is built using web technologies, a PhoneGap application with the exact same source code can be deployed across different platforms. It should be considered that phonegap has also some limitations as the front end of the application is built in JavaScript. A large number of applications rely on background threads to provide a smooth user experience, but as PhoneGap APIs are built using JavaScript which is not multi-threaded background processing is not supported. In addition a number of native APIs are not yet supported by PhoneGap’s APIs

A "Hello World" application can be created as follows:

1. Install SDK + Cordova

Download and install Eclipse Classic (Eclipse 3.4+) from http://www.eclipse.org/downloads/
Download and install Android SDK from http://developer.android.com/sdk/index.html
Download and install ADT Plugin http://developer.android.com/sdk/eclipse-adt.html#installing
Download the latest copy of PhoneGap from "http://phonegap.com/download" and extract its contents. We will be working with the Android directory.

2A. Setup your PATH environment variable on Mac OS

Open the Terminal program (this is in your Applications/Utilites folder by default).
Run the following command

touch ~/.bash_profile; open ~/.bash_profile

This will open the file in the your default text editor.
You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "/Development/android-sdk-macosx" as the directory the SDK is installed in. Add the following line:

export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools

Save the file and quit the text editor.
Execute your .bash_profile to update your PATH.

source ~/.bash_profile

Now everytime you open the Terminal program you PATH will included the Android SDK.

2B. Setup your PATH environment variable on Windows

From the Desktop, right-click My Computer and click Properties.
Click Advanced System Settings link in the left column.
In the System Properties window click the Environment Variables button.
Select the PATH variable from the System variables section.
Select the Edit button.
You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "C:\Development\android-sdk-windows" as the directory the SDK is installed in. Append the following text into the text box:

;C:\Development\android-sdk-windows\platform-tools;C:\Development\android-sdk-windows\tools

Save your edit. Close the Environment Variables dialog.
Additionally, you may need to include %JAVA_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type java. If the program can not be found add %JAVA_HOME%\bin to the PATH. You may need to specify the full path instead of using the %JAVA_HOME% environment variable.
Finally, you may need to include %ANT_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type ant. If the program can not be found add %ANT_HOME%\bin to the PATH. You may need to specify the full path instead of using the %ANT_HOME% environment variable.

3. Setup New Project

In a terminal window, navigate to the bin directory within the android subfolder of the Cordova distribution.

Type in ./create then press "Enter"

is the path to your new Cordova Android project
is the package name, e.g. com.YourCompany.YourAppName
is the project name, e.g. YourApp (Must not contain spaces)

Launch Eclipse, and select menu item New Project
Select the directory you used for
Click Finish.

4. Hello World

Create and open a new file named index.html in the assets/www directory. Paste the following code:

Cordova

Hello World

5. Deploy to Emulator

Right click the project and go to Run As > Android Application
Eclipse will ask you to select an appropriate AVD. If there isn't one, then you can create one as follows from the Android Virtual Device Manager:
- click "New" button from the Android Virtual Device Manager
- fill up the required information and click OK

6. Deploy to Device

Make sure USB debugging is enabled on your device and plug it into your system. (Settings > Applications > Development)
Right click the project and go to Run As > Android Application

The instalation tutorial can be found also under:
http://docs.phonegap.com/en/2.2.0/guide_getting-started_android_index.md...

Taggings:

Simple Hello-World-App on Android

Let's start with what you need first.

  • An Android phone, e.g. Samsung Nexus S or Galaxy Nexus
  • An IDE. Use Eclipse for Java EE.
  • The Eclipse ADT plugin (Android Dev Tools), available from Eclipse's own Package Installer.
  • The Android SDK-Tools, available from here

Install all software named in the upper list in this order. At one point, you'll be asked which Android versions you want to develop for. It is always a good idea to be on top of things, but don't forget to be compatible (more about this later). After you've done this, check whether any Android SDK-components are missing: In Eclipse, open "Window", "Android SDK Manager", and check whether the Android versions chosen by you are there.

The next step is to create the Hello-World-program. For this, in Eclipse: Open "File", "New", "Android Application Project" (might be hidden in "Other" the first time you open it). In this window, you'll have to make two important choices: What SDK-Version should be the "Minimum Required SDK"? What is the oldest Android phone you want your Hello-World-App to be compatible with? And: What is the "Target SDK"? For which SDK-Version do you want to develop this specific app.

Some words to Android-App-anatomy (or physiology): Every App consists of a number of "Activities", which interact wich each other by "Intents" and "Handlers". A lower layer, consisting of the "Service" and "AsyncTasks", is here to bring order to the chaos. Activities can be paused and resumed. Views are defined by XML-Files.

Now to the Hello-World-display: First, create a view in Eclipse. You should see an Android display. Name the resulting XML-file e.g. "activity_main.xml". Drag a Text-Field into the display of the phone. In the code, you should see an XML-particle, like:

< Text View
android:layout_width="wrap_content"
[..]
android:text="Hello World!" />

In the java-File of your main activity, be sure to set the view you've just created to be displayed on start-up. For this, you'll have to add a line of code to the activity's onCreate-method:

protected void onCreate(Bundle savedInstanceState) {
[..]
setContentView(R.layout.activity_main);
[..]
}

That's it. Plug in your phone, if you haven't already, and run the code in Eclipse. It should automatically deploy it to the phone - where an app symbol should appear. Run it, voilà!

Taggings:

Using USB tethering, wireless hotspot or Bluetooth connection

USB tethering

USB tethering is the best if you are only connecting one device to your phone, and that device has a USB port. If you are connecting multiple devices, or connecting a tablet with no USB port, you will want to use a wireless hotspot.

->Connect your phone to your laptop via the USB cable. You can ignore any pop ups on your computer about browsing files.
->Open your Settings. Either press your Menu button and select Settings, or open the Settings app in the App Drawer.
->Under “Wireless and network”, click “Tethering and portable hotspot”.You may have to click “More Settings” in order to find this option. Different Android systems will be structured in different ways, but the general steps are the same.
-> Check the “USB tethering” box. This will begin sending network data to your laptop. A blue connection icon will appear in your phone’s notification bar. If you are running Windows XP, you will need to download the “tetherxp.inf” file from the Android website. The file will need to be installed when you connect your phone to your computer for the first time.
-> Uncheck the box to stop sharing. You can also disconnect the USB cable to stop sharing.

Create a wireless hotspot

If you need to connect more than one device to your phone’s data plan, you will want to create a wireless hotspot. Be aware that this is less secure than using USB tethering. Also you must be aware that anyone with the password can connect and start using your data.

-> Open your Settings. Either press your Menu button and select Settings, or open the Settings app in the App Drawer.
-> Under “Wireless and network”, click “Tethering and portable hotspot”.You may have to click “More Settings” in order to find this option. Different Android systems will be structured in different ways, but the general steps are the same.
-> Check the box labeled “Portable Wi-Fi hotspot”. Depending on your device, this may be a slider labeled “Mobile Hotspot” or something similar. Slide it to turn it on. Once the device is broadcasting, a blue wireless icon will be added to your phone’s notification bar.
-> Tap the “Portable Wi-Fi hotspot settings” button to configure the name of your wireless network, as well as the security. It is highly recommended that you secure your network to keep unwanted users from accessing the network and draining your data plan.

Bluetooth connection

1)Set up your cellphone's Bluetooth connection so the phone is recognized by your laptop. Enabling your phone's Bluetooth setting allows the phone to send a Bluetooth signal to your laptop long enough for the computer to recognize the signal and find the cellphone.
2) Click "Start," then click "Control Panel."
3) Click on "Printers and Other Hardware," then click "Bluetooth Devices."
4) Click on "Add," then follow the instructions your PC provides.
5) Choose PAN (Personal Area Network).
6) If prompted for a PIN code, try 0000 or 1234 and enter it on both the mobile device when prompted and your computer.

Macbook laptop
1) Set up your cellphone's Bluetooth connection
2) Open the "Applications" folder, click on "Utilities," then click on "Bluetooth Setup Assistant."
3) Choose the "Mobile Phone" device option.
4) Follow the prompts on your laptop and complete the pairing/tethering procedure.

How to see all of the HTTP and SSL / HTTPS traffic of your Android smartphone

There are two ways to see the traffic of your phone.

The first one can only be used for Android versions 4.0 and higher.
First install a proxy application as Charles (http://www.charlesproxy.com/)
Then take your phone and navigate to the WIFI-Settings (settings->wi-fi). Make a long click on the connected network and select the "modify network" option. If you check the "show advanced options" you can scroll down a bit and see settings for proxy. Select the "manual" option and write the ip-address as proxy hostname and the port. If you are running Charles you can find the ip-address when navigating to Help->Local-Ip-Address.. The port for Charles is always 8888.
Save the settings and you are done. Now you see the whole traffic in the Charles-Session-Window. If you don't need the proxy anymore don't forget to remove it from the settings on your phone.

The second way is working for all Android versions.
First install a tool like Wireshark or Charles and use the proxy for your computer. Then use ethernet-connection and share the internet over wifi from your computer. Take your smartphone and select your shared wifi as the network.
And now you're done. You can see the whole traffic in your proxy-tool. The only disadvantages of this way are that you need an ethernet-connection and you see the traffic of your computer also.

Taggings:

How to implement autoresize/autorotate of Android Player?

To be able to change the View of the player depending on the rotation of the device we have to use the MediaPlayer-Class instead of the VideoView-Class.

So first you have to extend the SurfaceView and to catch the event when the size of the view is calculating. This event is called "OnMeasure" (From Android Documentary: OnMeasure - Called to determine the size requirements for this view and all of its children). So every time the view was changed and has to be drawn again or when the device rotates, this event will be called. This is the moment where we have to calculate the size of our surfaceView. Therefore we need to know the orientation of the device.

To be able to handle the orientation-changed-event we have to set a flag in the AndroidManifest class.
So for the activity, which will contain the mediaplayer, we have to set android:configChanges="screenSize|orientation". Now we can handle this event without a restart of our activity and pass the new orientation to our surfaceview.

@Override
public void onConfigurationChanged(Configuration _newConfig) {
if (mSurfaceView != null)
mSurfaceView.setConfiguration(_newConfig);
super.onConfigurationChanged(_newConfig);
}

Now our surfaceview is able to change the size depending on the orientation. To add it to our activity-layout we can add it to the xml as followed:

LinearLayout ...
package-name.AutoResizeSurfaceView
android:id="@+id/mediaplayer_surfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" /
...
/LinearLayout

So actually that's it. A possible implementation of the custom surfaceview is attached to this solution. The final step is to implement the mediaplayer, which uses our custom surfaceview.

The implementation of the mediaplayer is documented here:
http://developer.android.com/guide/topics/media/mediaplayer.html

And a really good example-project can be found in the platforms-examples which are part of the Android SDK.

Taggings:

Reverse engineering of Android Apps with baksmali and dex2jar

First of all you must get the .apk-file.

- Therefore you have to connect your Android-Phone with your computer over USB.
- If not already installed, load the Android SDK from here https://developer.android.com/sdk/index.html
- Open a terminal and navigate to Android SDK/platform-tools
- Run following command ./adb pull /data/app/-.apk
(You can find the package-name of the application in the market-url. For Example by https://play.google.com/store/apps/details?id=com.rovio.angrybirds the packe-name is "com.rovio.angrybirds". The Number is mostly 1 or 2.)
- Now you have the apk-file in the same folder on your computer and you can decompile it. Therefore there are 2 things you can do, so make two copies of the apk-file.
1. To get the graphics and layouts you have to download a tool named apktool from here http://code.google.com/p/android-apktool/
When the tool and the apk-file are in the same folder you can decompile it from the terminal with the following command:
./apktool d [PACKAGE-NAME]-[Nr].apk
Now you get a new folder with the whole project. You can't read the java-code, but the graphics and layouts are origin. If you want to do some funny stuff, you can replace so graphics and build a new apk with the comman
./apktool b [FOLDER] FUN_[PACKAGE-NAME]-[Nr].apk
You can install this apk running ./adb install FUN_[PACKAGE-NAME]-[Nr].apk
2. To get the java-files as a jar, so you can get a closer look to the package-structure and classes you have to rename your apk-file to jar and unzip it.
Now you have a classes.dex-file, which you can compile to smali-files with the following tool:
https://code.google.com/p/smali/
So after the dex->smali compiling you get the whole project but with smali-files instead of class-files. But the smali-files are a bit understandable, so sometimes it is possible to change the right code-snippet to get what you want.
If you don't want to change anything, you can compile back smali->dex with the same baksmali-tool.
Now download the last tool: https://code.google.com/p/dex2jar/
With this one you can compile the classes.dex-file to a jar-file, which you can include as a normal java-lib into your Andrpod project.

And that's it!

Taggings:

Use Phone as USB-Memory/Stick trough USB Cable

Precondition:
• Having a Computer that supports USB-Sticks (auto mounts it)
• Android-Phone (version Android 2.3 "Gingerbread")

Steps:
1. If USB-Cable is connected disconnect it from the devices
2. Enter into Phones -> Settings
3. Under Topic “Wireless and networks” is an entry “More ...” Click it
4. Click on “USB utilities”
5. “Connect storage to PC”
6. Now connect the USB cable to the Phone and to the USB connector of the PC
7. USB drive should appear on your pc! ;)

Helpful sites :
Under the assumption “A video says more than 1000 words”:
http://www.youtube.com/watch?v=j9LzT959Udg
http://www.youtube.com/watch?v=fXtZIQ-RHik

Dropbox - Storing and sharing files in the cloud

Dropbox is a web-based file hosting service which uses cloud computing to enable users to store and share files and folders with others across the Internet using file synchronization. You can download it at www.dropbox.com

Dropbox can be installed on Windows, Mac OS X, Linux, iPhone, iPad, Android devices and more. After creating an account and installing, you will find a folder called "My Dropbox". All files in this folder will be synchronized seamlessly to every other device that has Dropbox installed. If you can't install the client, you can still use the web interface at www.dropbox.com - just log in with your username and password in the upper right corner.

Dropbox also offers a version history and sharing features. Using the version history you can easily revert back to previous versions. The sharing features are great for collaborating on files and folders.

flashing CyanogenMod

To accomplish this we will install a customized, aftermarket firmware distribution named CyanogenMod.  This guide is optimized for the HTC Magic provided by A1/Vodafone in Austria. If you have another Android device you will have to choose accordant images. Download a recovery image from your favorite Android site or from the following resource and put it on your sd-card: http://n0rp.chemlab.org/android/Also download the HTC factory system image ( http://developer.htc.com/adp.html ) and the latest Cyanogen's ROM ( http://www.cyanogenmod.com/ ) and copy it into the root directory of your sd-card too. Start a terminal emulator on your rooted Android Phone and cd to /sdcard. The following command flashes the new recovery image:sudo flash-recovery cm-recovery-1.4.img You can start into recovery mode by holding down the home key on your device while rebooting. Before wiping all data a backup is recommended by selecting 'nandroid backup' from the recovery menu. After wiping apply the HTC factory system image and finally the latest ROM from cyanogen. The first boot of the new ROM will take longer than usual - just be patient - you can explore the new feature in some minutes.Be sure to install the CM-Updater to receive notifications for new updates and be able to download and apply them immediately.  

Taggings:

Pages

Subscribe to Android