Development

Android 2.2 – How to install apps directly in SD card

ome Android smartphones have low capacity internal memory and not allow you to install many apps.

At Android 2.2 there is a possibility migrate the apps to SD card after instalation, but some applications not allow to do this.

Looking for a fix to solve this problem in my Motorola Droid, I found a way to install apps directly in SD card, like show in Mundo Zoom, and not need root.

Download ZIP file from Android SDK and extract. Browse to folder “android-sdk-windows\platform-tools“.

Set your Android to debug mode. Don’t you know? “Settings” > “Applications” > “Development” and enable “USB debugging” option.

Connect your smartphone in USB and enable “Charge Only” on USB Connection Management.

Click in Start Menu, Run. Type “cmd” e press Enter to open command prompt.

With command prompt and Windows Explorer opened, click and drag file “adb.exe” to prompt window, after, insert a space and type “shell”. Press Enter.

The “$” simbol and cursor should appear. Now type “pm setInstallLocation 2” and press Enter

This command sets partition “2″ (SD Card) as default to install applications.

Done! That`s all you need for apps to be installed directly in your SD card


Why to use File.separator and File.pathSeparator

Java programmers knows about methods quoted in title, but many doesn’t care with them.

These methods are useful for programmer that do not knows wich characters represents file separator and path separator at OS that supports your application.

Linux/Unix, the methods File.separator and File.pathSeparator returns “/” and “.”, while in Windows, these methods returns “\” (or “\\” – escape) and “;”.

In recent case, the code below threw exception FileNotFoundException running over Linux, but not running over Windows:

String appPath = ctx.getRealPath();
String filePath = appPath + "\\" + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...

Worked in both systems after to replace “\\” by File.separator in line 2:

String appPath = ctx.getRealPath();
String filePath = appPath + File.separator + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...

Utilization of these methods, besides a good practice, is very usefull when same version of an application is running over differents operacional systems.


Apps can’t miss in your Android – RemoteControl for Earphones

I’m starting a new section called “Apps can’t miss in your Android“. This section will have reviews and tips for useful applications, that will help to extract all potentical from your Android.

I’ll start with RemoteControl for Earphones. It just cancel a vantage of iPhone over Android: to control media players using the earphones’s button.

The button’s behavior is to pause and start music. RemoteControl for Earphones allow you runs almost all commands of a media player. To play or pause, press button once, to skip forward, press button twice, to skip rewind, press four times…

RemoteControl for Earphones

App screen (Android Market)

This application is for free and don’t have advertisement.

Most players are incompatible, but it work very well in Morotola Droid’s player, Songbird, but not work in Winamp and players of Samsung Galaxy S and Motorola Atrix.

Link:  RemoteControl for Earphones
Price: Free
Advertisement: No


How to read and write CLOB fields

The Character Large Object (or CLOB) is a commonly found in databases and used to store high quantity of characters.

At MySQL, for example, this field is called MEMO.

Writing CLOB field

The method setAsciiStream of PreparedStatement allow to pass data to a CLOB.

ps.setAsciiStream(bindPosition, inputStream, textLength);

bindPosition – Position in PreparedStatment’s CLOB field.
inputStream – Used to pass data.
textLength – Data (text) length.

Full code:

String sql = "INSERT INTO TABLE (text) VALUES(?)";
		try{
			String txt = readTxtFile();
			ByteArrayInputStream bais = new ByteArrayInputStream(txt.getBytes());

			PreparedStatement ps = conexao.prepareStatement(sql);
			//CLOB is '?' at first position
			ps.setAsciiStream(1, bais, txt.length());

			ps.execute();

			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}

Retrieving CLOB data

We’re using SELECT clause, this clause returns a ResultSet to fetch data and, calling getClob method, passing column name or your position in the query, it give to you a Clob object.

rs.getClob("xml");

Full code:

String sql = "SELECT xml FROM TEST";
		try{
			PreparedStatement ps = conexao.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();

			while(rs.next()){
				Clob clob = rs.getClob("xml");
				BufferedReader reader = new BufferedReader(clob.getCharacterStream());
				StringBuffer strBuf = new StringBuffer();

				String linha = null;
				while((linha = reader.readLine()) != null){
					strBuf.append(linha);
//Character.LINE_SEPARATOR insert break line
					strBuf.append((char)Character.LINE_SEPARATOR);
				}

				System.out.println("=========== CLOB ===========");
				System.out.println(strBuf.toString());
			}

			rs.close();
			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}

That’s it! Easy and painless ;)

Download full code here

To write a BLOB see this tutorial.


Installing .apk packages at Android SDK emulator

Sometimes our applications depends of third-part applications for tests or to access resources of emulator that aren’t available by default.

In directories of SDK, commonly in platform-tools, there is an executable called adb, with it we’ll to install third-part applications.

You will need an application (.apk). Browse internet or copy from your Android smartphone using applications like AppSaver.

- Run the emulator, you can use SDK Manager or Eclipse plugins.

- Using DOS Command (Windows) or terminal (Linux), open directory platform-tools and run commando line below:

$ adb install <.apk path>

This message will be displayed

$ adb install Application.apk
125 KB/s (1091937 bytes in 8.474s)
        pkg: /data/local/tmp/Application.apk
Success

Now, the third-part application is available at emulator menu, like have installed in your smartphone.

Agora o aplicativo estará disponível no menu do emulador. ;)

 


  • AdSense

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress