Skip to content

Tag: Android

LG Optimus V 3G connection problem

When I came back from my last travel my 3G connection stopped working and seems that a lot of people already had the same problem. It was after I reactivated my plan when I came back to the US. Apparently they forgot to activate my data plan I’m paying for.

How to solve

I tried different things but finally I tried to simply activate the phone again using the Activate application (probably the first application on the list). After a few tries It worked and I got my 3G connection back.

Improve your battery life

One interesting thing is that during my days without 3G my battery life was quite better. So when you want to save battery, in travels for example, you can manually activate/deactivate your data plan on the Setting -> Wireless & networks settings -> Mobile Networks -> Data Enabled option.

Android screen height and width

Context ctx = getContext();
Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be smaller, but this code is more general.

palestra android

Essa quinta-feira, dia 6 de Maio de 2010, conversaremos sobre Android na palestra “Android: Visão Geral” a partir das 18:30 na Faculdade Evolução (R. Pedro I, 1276, no Centro). A ideia é falar por cima sobre o mercado mobile, o desenvolvimento Android, as possibilidades e os conceitos principais sobre suas aplicações.

Maiores detalhes sobre inscrição e a grade completa do evento:

Até lá.

Atualizado: slides que eu usei:

Android Flaw: cloning content

How to reproduce:

1. An application with a bunch of EditText.
2. Go to setup and change the locale of Android.
3. Back to the application.

Expected behavior

Locale changed and input values are the same.

Observed behavior

Input values from the last EditText is copied to all others. Even if it’s a password sensitive EditText.



	
	
	
	

Variations:
1. Same behavior in a EditText with default TransformationMethod.
2. DatePicker and TimePicker have strange behaviors too. They lose what I was writing on them but they don’t copy content.
3. The behavior was first noticed on the internal component NumberPicker and after that tested on EditText.

Malicious usage scenario:
Someone is filling user/password form in a application, go to the bathroom and forget the phone over a table. Other one gets it, use the flaw and read the user secret password.

Possible cause:
When locale is changed and you enter again in a application, it has to be destroyed and created but somehow old values are filled again. Probably the routine that cares about writing i18n details such orientation (left-to-right/right-to-left) has a bug.

Affected versions:

  • Android 1.6, tested on 2 devices and emulator.
  • Android 2.0, tested on device.
  • Certainly all versions between them and I guess 2.1 also.

Thanks to Diego Almeida who first noticed that behavior on NumberPicker. :]

Update: I filled a issue on Android project. Seems that they know about that behavior and the workaround is to put android:id properties on elements. The problem persists on NumberPicker even when using android:id on them! In fact, is my real problem.

Android: acessing internal resoures

a new android I just drew. source-code: android_look.svg. CC-BY-SA as usual.

You can acess internal Android resources such strings, drawables, layouts and others. For example, if you need to create a button with the text “Cancel” you can do:

Using this you are using the internal resource for “Cancel” in that Android and all its i18n. Using the same logic you can access drawables, layouts, etc.

Android TextView Shadow

How to add a shadow in a text view? How to improve the text readability on widgets?

There’s four properties on TextView related to shadows.

First a a normal TextView XML declaration.



Now the same TextView with the four shadow properties, the color, the x,y offset and the blur radius.



Getting an Android app source

Getting the Android’s AlarmClock application source from official repositories:

git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git

To get the head version for an old platform like the 1.4 (codename donut), choose the correspondent branch using -o or –origin:

git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git --origin donut

Getting enviroment information on Android

This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users.

Download:

  • WhoAmI.tar.bz2 – Eclipse project. It’s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions.
  • WhoAmI.apk – Application installation Android package.

Main Activity source code:

package net.silveiraneto.whoami;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.widget.EditText;

public class WhoAmI extends Activity {
    private EditText mEditor;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.whoami);

        mEditor = (EditText) findViewById(R.id.editor);

        Object[][] properties = {
        	{"Build.BOARD", Build.BOARD},
        	{"Build.BRAND", Build.BRAND},
        	{"Build.CPU_ABI", Build.CPU_ABI},
        	{"Build.DEVICE", Build.DEVICE},
        	{"Build.DISPLAY", Build.DISPLAY},
        	{"Build.FINGERPRINT", Build.FINGERPRINT},
        	{"Build.HOST", Build.HOST},
        	{"Build.ID", Build.ID},
        	{"Build.MANUFACTURER", Build.MANUFACTURER},
        	{"Build.MODEL", Build.MODEL},
        	{"Build.PRODUCT", Build.PRODUCT},
        	{"Build.TAGS", Build.TAGS},
        	{"Build.TIME", Build.TIME},
        	{"Build.USER", Build.USER},
        };

        for(Object[] prop: properties) {
        	mEditor.append(String.format("%s: %s\n", prop[0], prop[1]));
        }
    }
}

And its Android Manifest:



    
        
            
                
                
            
        
    

Capturas de Tela no Android

Quando desenvolvendo aplicações móveis para o Android as vezes precisamos obter imagens do dispositivo para comparar com um alguma referencia no computador. Como tirar screenshots no Android? Usar uma aplicação para isso e então passar as imagens para o computador? Não, há um jeito mais fácil.

Juntamente com o Android SDK há uma ferramenta na pasta tools chamada ddms (Dalvik Debug Monitor Server). O ddms ainda está pouco integrado com o plugin ADT do Eclipse e também pouco documentado, mas é extremamente útil para várias tarefas como monitoras o heap de memória, threads, processos e, é claro, tirar screenshots.

Para utiliza-lo com todas suas funcionalidades lembre-se de desligar primeiro o Eclipse (porque no momento só pode ter um aplicativo conectado ao ADB), porém que para fins de captura de tela isso não é necessário. Selecione um dispositivo, vá no menu Devices → Screen Capture (Control-S). Pronto, você tem no computador uma captura da tela do dispositivo.